Skip to content
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

Dependency issues building package from scratch #26

Closed
hannahker opened this issue May 10, 2024 · 3 comments
Closed

Dependency issues building package from scratch #26

hannahker opened this issue May 10, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@hannahker
Copy link

I'm trying to follow these instructions and build this package locally by:

  1. Cloning the repo
  2. Opening the project in RStudio
  3. ctrl + shift + b

But get the following error:

* installing to library '/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library'
ERROR: dependencies 'dplyr', 'ggplot2', 'ggthemes', 'magrittr', 'purrr', 'rlang', 'showtext', 'sysfonts', 'tibble' are not available for package 'gghdx'
* removing '/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/gghdx'

Exited with status 1.

I have a very fresh R install, so wondering if some of these dependencies need to be defined somewhere? Problem can be resolved if I manually install each package.

@hannahker hannahker added the bug Something isn't working label May 10, 2024
@caldwellst
Copy link
Collaborator

So all dependencies of an R package are defined in DESCRIPTION. Then you have to explicitly refer to them throughout package scripts in various ways, typically using package::object notation to reference the use of any dependency functions, datasets, or other exports. However, you cannot build a package without the dependencies installed. I saw what @zackarno recommended but not sure it works in the way described.

All of the shortcuts for building and installing and checking packages are available in the top right of RStudio, and are the same shortcuts used through the keyboard. In this case, ctrl + shift + b is the equivalent of Build.
image

However, they are also accessible as functions in the {devtools} package, like devtools::build(), devtools::install(), etc. which are utilities for local development. Useful to know because they are well documented and if you need to troubleshoot on SO or elsewhere, easier to reference those functions directly. devtools::build() builds a package, either a source package library that resembles what should be submitted to CRAN, or a binary package that is just a tarball you or others can use to install from. However, it doesn't install that package locally.

For that, you want to use devtools::install() which automatically installs the local package from any project you're working in, in this case. The install() function, like install.packages() also automatically installs any missing dependencies, so that will also solve your issue, as I don't think build() is designed to install dependencies if they aren't already present.

@caldwellst
Copy link
Collaborator

Oh, and to add, I think the easiest way to locally test is to just use devtools::load_all() (which will require you to have the package dependencies installed already). It simply loads all of the functions locally in to your environment and if you make a change to any function as you develop, you just rerun devtools::load_all()! The shortcut I use cmd + shift+ L.

@zackarno
Copy link
Collaborator

oh nice thats interesting! Guess i've always just been using the build workflow from the context of being a package developer with all dependencies already installed without realizing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants