inst/doc/approved.R

## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

library(logrx)

## -----------------------------------------------------------------------------
approved_pkgs <- list(base = "mean",
                      dplyr = "All")
approved_pkgs

## -----------------------------------------------------------------------------
build_approved(approved_pkgs)

## -----------------------------------------------------------------------------
dir <- tempdir()

build_approved(approved_pkgs, file = file.path(dir, "approved.rds"))

## -----------------------------------------------------------------------------
options(log.rx.approved = file.path(dir, "approved.rds"))

## -----------------------------------------------------------------------------
library(dplyr, warn.conflicts = FALSE)

results <- mtcars %>%
   group_by(cyl) %>%
   summarize(mean = mean(mpg)) %>%
   mutate(label = "Mean MPG")

results %>%
   tidyr::pivot_wider(names_from = cyl, values_from = mean, id_cols = label)

## ----echo = FALSE-------------------------------------------------------------
# write this to the temp directory so we have a script to axecute

text <- 'library(dplyr)

results <- mtcars %>%
   group_by(cyl) %>%
   summarize(mean = mean(mpg)) %>%
   mutate(label = "Mean MPG")

results %>%
   tidyr::pivot_wider(names_from = cyl, values_from = mean, id_cols = label)'
   
fileConn <- file(file.path(dir,"mpg.R"))
writeLines(text, fileConn)
close(fileConn)

## ----results='hide', echo = FALSE---------------------------------------------
fp <- file.path(dir,"mpg.R")
log_config(fp)
logrx:::run_safely_loudly(fp)
log_write(fp, remove_log_object = FALSE)

## ----echo=FALSE---------------------------------------------------------------
cleaned_log_vec <- c()

cleaned_log_vec <- c(cleaned_log_vec,
                           write_log_header("Used Package and Functions"),
                           write_used_functions())

cleaned_log_vec <- c(cleaned_log_vec,
                           write_log_header("Unapproved Package and Functions"),
                           write_unapproved_functions())
cat(cleaned_log_vec, sep = "\n")

## ----cleanup, echo = FALSE----------------------------------------------------
logrx::log_remove()

unlink(dir, recursive = TRUE)

Try the logrx package in your browser

Any scripts or data that you put into this service are public.

logrx documentation built on April 4, 2025, 2:07 a.m.