Publishing To Rpubs From The Command Line
Rpubs is a free service for publication of html-reports from R. Typically, the service is used to publish research. If you are working with R from the command line, there is a method for publishing to Rpubs – rpubsUpload.
Rpubs
Command Line Publication
Example
Conclusions
References
Rpubs
You can use Rpubs to publish and share R Markdown (.Rmd) files with others by employing the rmarkdown, markdown and knitr packages. The Rpubs-service is free,
Command Line Publication
The R Markdown format lets you combine R-code and text, and output the results to a markdown, html, pdf and a range of other formats with the knitr package (for more details on R Markdown and knitr, see Literate Statistical Programming From The Command Line. Markdown (.md) files can be published to Rpubs.
1. Load the necessary packages:
library(markdown) library(rmarkdown) library(knitr)
2. Run knit2html (from knitr) to create an html-file:
knit2html("your-path/your-filename.Rmd",output="path/filename.html")
This will create an html-file in the current working directory. knit2html has a bunch of options, but to create html files, only the input file is really required.
3. Publish to Rpubs using rpubsUpload:
rpubsUpload(title, "path/filename.html")
The title is the document title that is shown in the document overview in Rpubs. Note that you need to register an account with Rpubs to be able publish, see Rpubs.
NOTE: It is very important to save the ID-number that gets returned from Rpubs. You need this ID to make updates to the document.
.
To make updates, simply use:
rpubsUpload("path/filename.html", ID="the ID returned when you first published the document")
Example
First, we use knit from knitr to produce an html-file:
> knit2html("/home/eric/Git/ReproducibleResearch_CourseProject1/PA1_template.Rmd", output="/home/eric/Git/ReproducibleResearch_CourseProject1/PA1_template.html") processing file: /home/eric/Git/ReproducibleResearch_CourseProject1/PA1_template.Rmd |.. | 4% ordinary text without R code |..... | 7% label: setting_directory |....... | 11% ordinary text without R code |.......... | 15% label: loading_and_preprocessing |............ | 19% ordinary text without R code |.............. | 22% label: calculating_steps_per_day |................. | 26% ordinary text without R code |................... | 30% label: histogram_steps_per_day |...................... | 33% ordinary text without R code |........................ | 37% label: mean_median_steps_per_day |.......................... | 41% ordinary text without R code |............................. | 44% label: average_steps_per_interval |............................... | 48% ordinary text without R code |.................................. | 52% label: average_interval_w_maximum_steps |.................................... | 56% ordinary text without R code |....................................... | 59% label: total_NAs |......................................... | 63% ordinary text without R code |........................................... | 67% label: imputing_steps |.............................................. | 70% ordinary text without R code |................................................ | 74% label: histogram_of_imputed_steps |................................................... | 78% ordinary text without R code |..................................................... | 81% label: mean_median_imputed_steps |....................................................... | 85% ordinary text without R code |.......................................................... | 89% label: categorizing_days |............................................................ | 93% ordinary text without R code |............................................................... | 96% label: interval_by_day_type |.................................................................| 100% ordinary text without R code output file: PA1_template.md >
In spite of the lonely “output file: PA1_template.md”, there is also an html-file in the folder. Note that this process also creates graphical output, by default saved to the figure-folder in the same directory as the html-file. We can have a look at the file by using browseURL:
> browseURL("/home/eric/Git/ReproducibleResearch_CourseProject1/PA1_template.html")
Next, we publish to Rpubs:
> rpubsUpload("Counting Steps", "/home/eric/Git/ReproducibleResearch_CourseProject1/PA1_template.html") $id [1] "https://api.rpubs.com/api/v1/document/******/**********************" $continueUrl [1] "http://rpubs.com/publish/claim/******/**************************" >
We right-click on the continueUrl in the terminal and choose Open Link. If we haven’t already logged into Rpubs, we get the following page:
Next, we get a page with the same title as the one we filled out in the rpubsUpload-command above. We fill out the rest of the fields:
Next, we get a document view. We can leave things as they are, or delete the document if the result isn’t what we wanted:
Note that the figures in the figures-folders are published within the document:
The document now appears on your Rpubs-profile:
Conclusions
A combination of knit and rpubsUpload – from the knitr and markdown packages, respectively – makes it really easy and fast to publish html-files generated from Rmd-files to Rpub.
References
rpubsUpload {markdown} – R documentation – Downloaded February 2, 2018.
Rpubs – Getting Started – Downloaded January 31, 2018.
Rpubs page with example-document – Uploaded 21 February, 2018.
Git repository with example-files – Last pushed 21 February, 2018.
0 comments