FRBCesab / rcompendium

:package: Create a package or compendium structure
https://frbcesab.github.io/rcompendium
GNU General Public License v2.0
39 stars 8 forks source link

rcompendium::new_compendium() : ✖ No 'NAMESPACE' file found #69

Open morfogeno opened 1 week ago

morfogeno commented 1 week ago

After creating a new project folder in Rstudio called comp and running the command "rcompendium::new_compendium() " everything seems to be installed correctly, except when checking the dependencies, as attached below:

Checking for Dependencies

✖ No 'NAMESPACE' file found ✔ Scanning 'Depends' dependencies ◉ No package found ✔ Scanning 'Imports' dependencies ◉ No package found ✔ Scanning 'Suggests' dependencies ◉ No package found

When looking the files and folders created, there is no NAMESPACE file nor a comp.Rproj file. Below, the link of my github as generated by "rcompendium::new_compendium() :+1:

https://github.com/morfogeno/comp

ahasverus commented 1 week ago

Hi @morfogeno :wave:

Thanks for using rcompendium!

When working with a research compendium (new_compendium()), the NAMESPACE file and man/ folder are added to the .gitignore of your project. These files are important when developing a package but not useful (in my opinion) for a compendium. These files are not sent to GitHub, but you can generate them locally w/:

devtools::document()

Note that ✖ No 'NAMESPACE' file found is just a message and not an error.

RStudio files (comp.Rproj in your case) are also added to the .gitignore and are not sent to GitHub to avoid git conflicts (due to different versions of the IDE when collaborating w/ people). But this file exists locally.

If you want to collaborate w/ someone else, your collegue has to create a new RStudio project from Version control: this way, your colleague has RStudio files specific to his/her version of RStudio Desktop.

Nicolas

morfogeno commented 1 week ago

Thank you, Nicolas, for your response and very nice software! I am still studying how to migrate from my simple, isolated R scripts to a package/compendium frame. I thought I would need NAMESPACE in order to write my dependencies. I still don´t know how to add them. Is it enough if a manually add each dependency one-by-one with the command  "usethis::use_package()" ? Or should I write it somewhere else? Or is there a more automatic way to add it?

Another doubt, what happens if I add new folders in my project,  will they be read, for instance, by renv? Thanks again, and sorry if my questions are not the purpose of this github issues space.

ahasverus commented 1 week ago

No problem.

Your project dependencies must be declared in the DESCRIPTION file, not in the NAMESPACE. You have two ways to list packages in this file:

Depends: here

When running devtools::load_all(), the package here will be loaded and attached. This means that you can access its functions directly (i.e. here()). Listing package in Depends will have the same effect as library().

But it's recommended to list packages in the DESCRIPTION like this:

Imports: here

When running devtools::load_all(), the package here will be loaded only. To use the function here() in your script, you have to call it like this: here::here(). This will ensure you that you are using the function here() from the package here.

For instance, the function filter() from dplyr will mask the function filter() from the base package if you use library(dplyr). So it's safer to use a function with this syntax pkg::fun() and to list pkg in the Imports tag of the DESCRIPTION. This way you can securely use both functions: dplyr::filter() and filter() (from base package).

I recommend you to have a look at this book, especially the Chapter 9.6.

To add packages in the DESCRIPTION file, you can:

Note that I built rcompendium to works perfectly with renv.

Finally, you can create as many subdirectories as you want. rcompendium proposes a structure, but you are free to use yours.

Nicolas

morfogeno commented 4 days ago

Thanks!!