diff --git a/vignettes/generate-lockfile.Rmd b/vignettes/generate-lockfile.Rmd new file mode 100644 index 0000000..3bdd46e --- /dev/null +++ b/vignettes/generate-lockfile.Rmd @@ -0,0 +1,71 @@ +--- +title: "Generate renv lockfile from log file" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{generate-lockfile} + %\VignetteEncoding{UTF-8} + %\VignetteEngine{knitr::rmarkdown} +editor_options: + chunk_output_type: console +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +```{r setup} +library(logrx) +library(stringr) +library(dplyr) +library(renv) +``` + +Axecute a script and get the logfile. + +```{r run_axecute, echo = FALSE} +scriptPath <- tempfile() + +logDir <- tempdir() +writeLines( + c( + "print('hello logrx')", + "library(dplyr)", + "count(iris, Species)" + ), + con = scriptPath +) + +filePath <- file.path(logDir, "log_out_parse") + +axecute(scriptPath, log_name = "log_out_parse", log_path = logDir) +``` + +Later on read (and parse) previous log file as list of objects. + +```{r read_logfile} +parsedFile <- read_log_file(filePath) +``` + +Create a renv lockfile based on the used packages mentioned in the logfile. + +```{r gen_lockfile} +used_pgks <- parsedFile$`Used Package and Functions` %>% + transmute(package_name = str_extract(library, "(?<=package\\:).+")) + +temp_lockfile <- tempfile(fileext = ".lockfile") + +x <- renv::lockfile_create( + type = "custom", + packages = used_pgks$package_name +) + +renv::lockfile_write( + lockfile = x, + file = temp_lockfile, + type = "custom", +) +``` +