Pakillo / grateful

Facilitate citation of R packages
https://pakillo.github.io/grateful/
Other
221 stars 18 forks source link

Simple cite_packages call results in error #47

Closed npb596 closed 3 months ago

npb596 commented 3 months ago

Hello,

I am trying to use grateful for the first time and finding an error with what I assume is the simplest use case. So I'm not sure if I'm missing some obvious point in the documentation or if there is a more subtle issue here. I have an R script running in Rstudio like so just to test grateful:

setwd('~/SLiMulation') library(grateful) cite_packages(out.dir = getwd()) library(tidyverse) ggplot()

and receive the following error when running the cite_packages line: Error in dirname(root) : a character vector argument expected

I have tried specifying "." as the out.dir instead as well as exactly copying the above setwd "~/SLiMulation" into the out.dir option. The directory definitely exists, and is given as the directory with getwd(), and I've tried just using the home directory "~" in setwd, which also clearly exists too. Since the error specifies it's looking for a character vector I've also used class() to check that indeed getwd() is returning a character. I've also tried not specifying out.dir at all but receive the following error:

Error in cite_packages() : Please specify where to save the citation report, e.g. out.dir = getwd()

I wondered if the issue happens when no packages are used, so I also have tried running the cite_packages command individually after already loading tidyverse and running ggplot, so there is definitely one active package to cite. I was running somewhat older versions of R and Rstudio before, when I first got the error, and updated both to 4.4.0 and 2024.04.2 respectively, and still receive the error.

Thank you for your time, Nick

Pakillo commented 3 months ago

Hi Nick

Thanks for trying grateful, and the clear error report.

That error comes from renv, which grateful uses to detect all the packages used. Based on this issue it seems the error could stem from having a large number of files within your working directory, which {renv} struggles to manage. Does that make sense?

I think you can get it to work by specifying the root directory where {renv} should look, e.g.

cite_packages(out.dir = getwd(), root = getwd())

If you have all scripts within a subfolder it may make sense to specify that as the root, to avoid {renv} looking into all the other non-R files.

Hope this helps

Cheers

npb596 commented 3 months ago

Hi Francisco,

Running exactly the command you gave works. The directory does contain several sub-directories with many files, so that makes sense. Running the command you gave makes this pretty clear because it generates warnings that the sub-directories have many files and ignores them but the process is still very quick so it's not an issue, I now do get an output file as expected. I am very "grateful" for the help, thanks!

Cheers

Pakillo commented 3 months ago

Glad it worked! Thanks for letting me know

Cheers