Skip to contents

In this example we are going to execute the following script and create a log of it’s execution:

example.R:

#' Setup

library(dplyr)
library(ggplot2)

#' Prepare data

x <- mtcars |>
  as_tibble(rownames = "car")

print(x)

#' Create and save plot

ggplot(data = x) +
  geom_point(mapping = aes(x = mpg, y = hp, size = wt, colour = as.factor(am)))

ggsave("plot1.png")

We are going to use the run() function to execute the script, and since this vignette is created on Linux we can use the whirl.track_files option to automatically track the used files:

library(whirl)

options(whirl.track_files = TRUE)
options(whirl.verbosity_level = "minimal")

The verbosity_level is set to minimal for nicer printing in this vignette. Now we are ready to execute the script:

result <- run("example.R")
#> ══ Executing scripts and generating logs ═══════════════════════════════════════
#> → Executing scripts in parallel using 1 cores
#> The following steps will be executed
#>  Step 1: Unnamed chunk
#> 
#> 
#> ── Step 1: Unnamed chunk ───────────────────────────────────────────────────────
#> 
#>  example.R: Completed succesfully
#> 
#> 
#> ══ End of process ══════════════════════════════════════════════════════════════

print(result)
#> # A tibble: 1 × 6
#>      id tag   script                                 status result       log_dir
#>   <dbl> <chr> <chr>                                  <chr>  <list>       <chr>  
#> 1     1 NA    /tmp/RtmpeaqwRR/file22ffef05393/examp… succe… <named list> /tmp/R…

The script is now executed and you can access the logs below: