CredibilityLab / groundhog

Reproducible R Scripts Via Date Controlled Installing & Loading of CRAN & Git Packages
https://groundhogr.com/
GNU General Public License v3.0
78 stars 4 forks source link

Error: cannot coerce type 'closure' to vector of type 'character' #102

Closed farshid-vahid closed 1 year ago

farshid-vahid commented 1 year ago

When attaching libraries

library(groundhog)
today <- "2023-08-08"
groundhog.library(xts,today)
groundhog.library(demography,today)
groundhog.library(tidyverse,today)
groundhog.library(readxl,today)
groundhog.library(ggplot2,today)
groundhog.library(forecast,today)

it attaches all libraries successfully until it gets to the last one (forecast) and then stops with the following message:

Error in as.character(text) :
cannot coerce type 'closure' to vector of type 'character'
3. regexpr("library\\(", x)
2. sandwich.library(pkg)
1. groundhog.library(forecast, today)

The last three lines are given after I click on show traceback in RStudio 2023.06.1+438 "Mountain Hydrangea" Release (0854207b2c64f6a7049e668177d2753b7e69d57a, 2023-06-27) for windows Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) RStudio/2023.06.1+438 Chrome/110.0.5481.208 Electron/23.3.0 Safari/537.36. I am using R version is 4.3.1 and groundhog version 3.1.0 on Windows.

urisohn commented 1 year ago

I suspect the object 'forecast' exists in your environment and when groundhog processes it as an object, rather than pkg name (expecting a character object) R produces the error because it is not a character object.

If you put "forecast" in quotes it should work.

I will put in my to do list for groundhog future revisions to build a data-check at that point to ensure the vector is character.

Note that you can put all packages in a string vector and do it all in one call

pkgs=c(pkgA, pkgB, pkcC)
groundhog.library(pkgs, date)

I would recommend always putting pkg names in quotes, and using a stable date, so for instance, using 2023-07-01 until you update the R version (to reduce # of pkgs that you need to install).

urisohn commented 1 year ago

I have added more robustness to this kind of ambiguity, now, if the argument for pkg is not a character object, it puts it in quotes, so it should seemlessly resolve conflicts like this one. Should go in version groundhog V3.1.1, to be submitted to CRAN later today.