Closed yonicd closed 3 years ago
drake
does not set an environment variable to indicate make()
or r_make()
is running. Is that what you were asking? I'm not sure I understand the use case.
i have this type of rmd
---
title: "Analysis"
author: "Jonathan Sidi"
date: "`r Sys.Date()`"
output:
bookdown::html_document2: default
bookdown::word_document2:
fig_width: 6
fig_height: 6
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = FALSE,
message = FALSE,
warning = FALSE,
fig.path = '../../deliv/figures/',
fig.topcaption=TRUE
)
library(officedown)
library(magrittr)
library(ggplot2)
library(patchwork)
library(drake)
source(here::here('script/utils.R'))
...
the _drake.R file has it in it too
```r
library(magrittr)
library(drake)
source(here::here('script/utils.R'))
source(here::here('script/plan.R'))
drake_config(plan, verbose = 2)
I want to be able to run this file both standalone and through drake.
If I run this rmd standalone it runs ok and outputs the html in the directory where the file is saved. But if I try to run it in a drake plan it breaks because of the file is sourced twice.
if i set eval=FALSE
then the Rmd isn't standalone anymore.
If there was a way to know if drake is in runtime then I could add a flag in the rmd chunk.
Does this description make sense?
Seems like the sort of thing that should work. Which file is sourced twice? What kinds of things are in the rest of the Rmd? Does the Rmd call r_make()? Because then that would definitely cause problems. A report can wrap around drake or run within drake, but not both.
the script/utils.R
which is a file with helper functions that are placed in the runtime envir. I wanted to source it in _drake.R
because I use the functions in multiple targets
when lock_envir=TRUE
I get this error (map_sas_drive
is the first function in that file)
Quitting from lines 34-35 (periods.Rmd)
Error : target period_report failed.
diagnose(period_report)$error$message:
cannot change value of locked binding for 'map_sas_drive'.
Please read the "Self-invalidation" section of the make() help file.
diagnose(period_report)$error$calls:
base::source(here::here("script/utils.R"))
base::withVisible(eval(ei, envir))
base::eval(ei, envir)
base::eval(ei, envir)
Error: callr subprocess failed: target period_report failed.
diagnose(period_report)$error$message:
cannot change value of locked binding for 'map_sas_drive'.
Please read the "Self-invalidation" section of the make() help file.
diagnose(period_report)$error$calls:
base::source(here::here("script/utils.R"))
base::withVisible(eval(ei, envir))
base::eval(ei, envir)
base::eval(ei, envir)
Type .Last.error.trace to see where the error occured
Ah, I see what you mean now. I recommend two alternatives. Either:
Prework
Question
What would you like to know?
Is there a runtime environment variable that can be checked for when drake runs to skip certain chunks in an Rmd document. In the same spirit of
{r my chunk, eval = knitr::opts_knit$get("child")}
?Reproducible example