2
votes

I created my first R package and have a question.

The package runs successfully on my computer. However, if my users (who do not have the packages required) run my package, they will get an error saying the required package is not available. When they manually install that package from CRAN, then my package would work.

According to Hadley Wickam's book (http://r-pkgs.had.co.nz/description.html):

Imports: packages listed here must be present for your package to work. In fact, any time your package is installed, those packages will, if not already present, be installed on your computer (devtools::load_all() also checks that the packages are installed).

I put all the required packages in the Imports field in DESCRIPTION. How come that required package is not installed automatically? Do my users need to install all the required packages before using mine?

Additional background:

  1. I use the convention package_name::function_name in my script.
  2. I distribute the package as a binary package.
  3. The users install the package from their local directory so they can't specify DEPENDENCIES=TRUE when calling install.packages.

What I've done:

  1. Read Hadley Wickham's book R Packages
  2. Read Imported packages do not auto-install and R package dependencies but didn't find any information for my issue.

Thank you!

2
So your package isn't installed from CRAN or GitHub?Dason
The question you link about imported packages not auto-installing seems to be nearly an exact duplicate. install.packages will look in the specified repository for dependencies to install. If you are just having users install locally, there is no repository and no dependencies are installed. Dirk recommends using his package drat to make your own little repository with all your dependencies if you don't want to deal with CRAN.Gregor Thomas
This: "any time your package is installed, those packages will, if not already present, be installed on your computer " is not in general true. THere was either an error in Hadley's thinking when he wrote that or (more likely) you have not given a complete description of the context for that statement. You need to take specific steps to have dependencies installed. There is a "dependencies" parameter in install.packages but I suspect that Hadley was using some special purpose function whose deployment was upstream of that text excerpt.IRTFM
Dason, yes, it's meant to use within our team. So I have been distributing it via e-mail. Our next plan is to host it on a shiny server.Ketty
Gregor, thank you! Yes, they are nearly identical. I am wondering if there is another way to do this besides using drat. Thanks.Ketty

2 Answers

1
votes

You can try to use

devtools::install_deps()

or

devtools::install_deps("pkg_version.tar.gz")

However, there seem to be some issues with this function, c.f. https://github.com/r-lib/devtools/issues/1370

The alternative would be using drat as suggested in the linked question.

0
votes

Just found that the dependencies were not installed because my package is not installed from a CRAN repo.

Using devtools::install_local("pkgname.tar.gz") will install the package and any dependencies.