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] 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) +``` +