library("jrAutomate") library("shiny") library("flexdashboard")
x = rnorm(10) plot(x) pdf("fileA.pdf") plot(x) dev.off()
filename
with the value file1.pdf
params$filename
fileA.pdf
, pass the parameter from the YAML headerfile1.pdf
params
section from the YAML headerfilename
parameter via the render()
functionrmarkdown::render("MyDocument.Rmd", params = list( filename = "file2.pdf" ) )
file2.pdf
Unfortunately, to run scheduler tasks it depends on
This means it's hard to get an exercise that will suit everyone. To get the
general idea across I've created a simple function called scheduler()
.
When we run the same script multiple times, there are two possibilities:
Create a standard Rmd file (don't worry about params
). In the body of the document
include
x = rnorm(10) plot(x) pdf("fileA.pdf") plot(x) dev.off()
We want to change fileA.pdf
to be unique. The easiest way is to use current time.
In R we have
Sys.Date() Sys.time()
In this exercise we'll use Sys.time()
, but you may find Sys.Date()
more suitable in general.
We need to convert the time to a file name. First convert it to a character
fname = as.character(Sys.time())
Then add on a pdf
file extension using the paste0()
function
fname = paste0(as.character(Sys.time()), ".pdf")
Now change fileA.pdf
to use fname. Run your script and ensure that it works.
The scheduler()
function is simple. It has three arguments:
rmd_name
: The name of Rmd
script you want to generaterepeats
: How often should we run the script (from now)time_between
: The time between script callslibrary(jrAutomate) ## time_between is in seconds scheduler(script_name = "my_script.Rmd", repeats = 5, time_between = 5)
Using the schedular()
function, run your Rmd
file 5 times with a 3 second interval.
Function name | Description
--------------|------------
dir.create()
| Creates a new directory
dir.exists()
| Checks a directory exists
file.create()
| Creates a new file
file.exists()
| Checks a file exists
file.remove()
| Removes a file
file.info()
| Size, creation date, etc.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.