The goal of pubr is to convert reproducible R scripts and Rmd contents into a publishable HTML block. It makes it easy to share reproducible R code in (wordpress) website comments and blog posts.
Install the pubr
package:
if(require(devtools)) install.packages("devtools")
devtools::install_github("kassambara/pubr")
Load the package:
library("pubr")
Note that, if you are using Rstudio on linux, make sure you have
installed the following system dependencies that make it easy to
interact with clipboard: xclip
or xsel
. This can be installed using
for example apt-get install xclip
in bash terminal.
- Write a pure R script in Rstudio
- Select and copy the script
- Run
pubr::render_r()
. The output of the rendered R script is a HTML block, which is automatically copied into the clipboard. - Paste into a website comment areas or into a blog post
# Load required package
suppressPackageStartupMessages(library(ggpubr))
# Data preparation
data("ToothGrowth")
df <- ToothGrowth
df$dose <-as.factor(df)
# Create a boxplot
ggboxplot(df, x = "dose", y = "len")
- Write a pure R script in Rstudio
- Copy the data from an Excel spreadsheet and paste it into R using
the function
pubr::paste_data()
- Select and copy the script
- Run
pubr::render_r()
. The output of the rendered R script is a HTML block, which is automatically copied into the clipboard. - Paste into a website comment area or into a blog post
# Data preparation
df <- pubr::paste_data()
# Summary statistics
summary(df)
- Write a pure R script in Rstudio
- Paste your data into R using the function
pubr::paste_data(data_file)
- Select and copy the script
- Run
pubr::render_r()
. The output of the rendered R script is a HTML block, which is automatically copied into the clipboard. - Paste into a website comment area or into a blog post
# Data preparation
data_file <-system.file("demo_data", "toothgrowth.txt", package = "pubr")
df <- pubr::paste_data(data_file)
# Create a boxplot
summary(df)
- Write an Rmd (without yaml header) from Rstudio
- Select and copy the Rmd content
- Run
pubr::render_rmd()
. The output of the rendered Rmd content is a HTML block, which is automatically copied into the clipboard. - Paste into a website comment area or into a blog post