Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
farshid-vahid opened this issue Aug 11, 2023 · 2 comments
Closed

Comments

@farshid-vahid
Copy link

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
Copy link
Collaborator

urisohn commented Aug 12, 2023

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
Copy link
Collaborator

urisohn commented Aug 21, 2023

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.

@urisohn urisohn closed this as completed Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants