I have different versions of tidyverse installed in a project renv and on my system. When I execute my project using a Makefile, it doesn't use the renv versions for some reason, instead using the system-wide versions. When I execute the code in the R file directly it uses the renv versions.
Could this have something to do with the initialization locations? renv was initialized in the project root folder but the Makefile is in the code folder, one level down.
Would appreciate any advice!
Thanks, Doron
EDIT: apologies, was unclear to me what information would be useful due to the nature of the issue.
My Makefile looks like this:
imp := import/
fn := functions/
mw := merge_wealthSupplement/
cm := clean_merged/
ccl := clean_clans/
mc := merge_clans/
cv := clean_variables/
dsc := descriptives/
an := analysis/
o := output/
i := input/
s := src/
targets := $(dsc)output/%.pdf
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
R = R --vanilla --args "" < "$<" "$(mkfile_path)" # $< marks the first prerequisite
all: $(targets)
# Import data from PSID needs username and password so can't run automatically
# $(imp)$(o)data.Rds: $(imp)$(s)import.R
# R --vanilla --args "" < "import/src/import.R"
$(mw)$(o)merged.Rds: $(mw)$(s)merge_wealthSupplement.R $(imp)$(o)data.Rds
$(R)
$(cm)$(o)clean_merged.Rds: $(cm)$(s)clean_merged.R $(mw)$(o)merged.Rds $(fn)$(s)functions.R
$(R)
$(ccl)$(o)sample.Rds: $(ccl)$(s)clean_clans.R $(cm)$(o)clean_merged.Rds $(fn)$(s)functions.R \
$(ccl)$(s)functions.R
$(R)
$(mc)$(o)merged_clans.Rds: $(mc)$(s)merge_clans.R $(ccl)$(o)sample.Rds \
$(cm)$(o)clean_merged.Rds $(fn)$(s)functions.R
$(R)
$(cv)$(o)clean_variables.Rds: $(cv)$(s)clean_variables.R $(mc)$(o)merged_clans.Rds
$(R)
$(targets): $(dsc)$(s)descriptives.R $(cv)$(o)clean_variables.Rds $(an)$(s)analysis.R
$(R)
.PHONY: clean
clean:
rm $(objects)
It is saved in .../project_name/code/Makefile
The R script where I notice the problem is the fourth makefile execution command: clean_clans.R
clean_clans.R starts like this:
if (!require("pacman")) install.packages(
"pacman", repos = "http://cran.us.r-project.org")
pacman::p_load(tidyverse)
It is saved in .../project_name/code/clean_clans/src/clean_clans.R
The renv lockfile is in .../project_name/renv.lock
When I execute clean_clans.R from the file itself there is no problem. When I execute it via Terminal it errors upon getting to pick()
, which was introduced in a newer dplyr version.
When I print out sessionInfo
I see that all the package versions are consistent with the renv lockfile when I execute the code directly from the file, but are consistent with the system (not the lockfile) when I execute from the Makefile.
Thanks so much for all the help and I would be happy to supply any further info! Doron