### Get path to example source
examplePath <-
system.file("extdata", package="rock");
### Get a path to one example file
exampleFile <-
file.path(examplePath, "example-1.rock");
### Get a temporary file to write to
tempFile <- tempfile(fileext = ".rock")
### For R versions below 4.1
loadedSource <-
rock::load_source(exampleFile);
loadedSource <-
rock::code_source(
loadedSource,
c("Lorem Ipsum" = "lorumIpsum")
);
rock::write_source(
loadedSource,
tempFile
);
### From R 4.1 onwards, you can also chain
### these commands using the pipe operator.
###
### Note that that means that this example
### will not run if you have a previous
### version of R.
loadedSource <-
rock::load_source(exampleFile) |>
rock::code_source(c("Lorem Ipsum" = "lorumIpsum")) |>
rock::write_source(tempFile);
Run the code above in your browser using DataLab