Create a (reproducible) report using R
The Report > R tab allows you to run R-code with access to all functions and data in Radiant. By clicking the
Knit report (R) button, the code will be evaluated and the output will be shown on the right of the Report > R page. To evaluate only a part of the code use the cursor to select a section and press
CMD-enter on mac).
You can load an R-code file into Radiant by clicking the
Load report button and selecting an .r or .R file. If you started Radiant from Rstudio you can save a report in HTML, Word, or PDF format by selecting the desired format from the drop-down menu and clicking
Save report. To save just the code choose
R from the dropdown and press the
Save report button.
If you started Radiant from Rstudio, you can also click the
Read files button to browse for files and generate code to read it into Radiant. For example, read rda, rds, xls, yaml, and feather and add them to the
Datasets dropdown. If the file type you want to load is not currently supported, the path to the file will be returned. The file path used will be relative to the Rstudio-project root. Paths to files synced to a local Dropbox or Google Drive folder will use the
find_gdrive functions to enhances reproducibility.
As an example you can copy-and-paste the code below into the editor and press
Knit report (R) to generate results.
## get the active dataset and show the first few observations .get_data() %>% head() ## access a dataset diamonds %>% select(price, clarity) %>% head() ## add a variable to the diamonds data diamonds <- mutate(diamonds, log_price = log(price)) ## show the first observations in the price and log_price columns diamonds %>% select(price, log_price) %>% head() ## create a histogram of prices diamonds %>% ggplot(aes(x = price)) + geom_histogram() ## and a histogram of log-prices using radiant.data::visualize visualize(diamonds, xvar = "log_price", custom = TRUE) ## open help in the R-studio viewer from Radiant help(package = "radiant.data") ## If you are familiar with Shiny you can call reactives when the code ## is evaluated inside a Shiny app. For example, if you transformed ## some variables in Data > Transform you can call the transform_main ## reacive to see the latest result. Very useful for debugging # transform_main() %>% head() head()
The editor used in Report > Rmd and Report > R has several options that can be set in
vim.keysenables a set of special keyboard short-cuts. If you have never used VIM you probably don’t want this
showInvisiblesshows tabs and spaces in the editor
For an overview of related R-functions used by Radiant to generate reproducible reports see Report