From 86b0ce084c20a9d8fcb3dbd19d43c080a21344a1 Mon Sep 17 00:00:00 2001 From: Sam Parmar <107635309+parmsam-pfizer@users.noreply.github.com> Date: Fri, 22 Sep 2023 17:14:49 -0400 Subject: [PATCH 1/2] draft lockfile read vignette --- vignettes/generate-lockfile.Rmd | 72 +++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 vignettes/generate-lockfile.Rmd diff --git a/vignettes/generate-lockfile.Rmd b/vignettes/generate-lockfile.Rmd new file mode 100644 index 0000000..35f7310 --- /dev/null +++ b/vignettes/generate-lockfile.Rmd @@ -0,0 +1,72 @@ +--- +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) +``` + + +```{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) + +parsedFile <- read_log_file(filePath) +``` + + +```{r read-previous-logfile} +# check that the log file can be parsed +parsedFile$`Used Package and Functions` +``` + +```{r 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 +) + +renv::lockfile_write( + lockfile = x, + file = temp_lockfile, + type = "custom", +) + +readlines(temp_lockfile) +``` + From 634e5da8c5a73dfcaf2f2be54acb4d59c0fce510 Mon Sep 17 00:00:00 2001 From: Sam Parmar <107635309+parmsam-pfizer@users.noreply.github.com> Date: Sun, 24 Sep 2023 20:18:14 -0400 Subject: [PATCH 2/2] update vignette with short sentences --- vignettes/generate-lockfile.Rmd | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/vignettes/generate-lockfile.Rmd b/vignettes/generate-lockfile.Rmd index 35f7310..3bdd46e 100644 --- a/vignettes/generate-lockfile.Rmd +++ b/vignettes/generate-lockfile.Rmd @@ -23,8 +23,9 @@ library(dplyr) library(renv) ``` +Axecute a script and get the logfile. -```{r run-axecute, echo = FALSE} +```{r run_axecute, echo = FALSE} scriptPath <- tempfile() logDir <- tempdir() @@ -40,17 +41,17 @@ writeLines( filePath <- file.path(logDir, "log_out_parse") axecute(scriptPath, log_name = "log_out_parse", log_path = logDir) - -parsedFile <- read_log_file(filePath) ``` +Later on read (and parse) previous log file as list of objects. -```{r read-previous-logfile} -# check that the log file can be parsed -parsedFile$`Used Package and Functions` +```{r read_logfile} +parsedFile <- read_log_file(filePath) ``` -```{r lockfile} +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\\:).+")) @@ -58,7 +59,7 @@ temp_lockfile <- tempfile(fileext = ".lockfile") x <- renv::lockfile_create( type = "custom", - packages = used_pgks + packages = used_pgks$package_name ) renv::lockfile_write( @@ -66,7 +67,5 @@ renv::lockfile_write( file = temp_lockfile, type = "custom", ) - -readlines(temp_lockfile) ```