I'm trying to deploy my R package on a local repository with its dependencies.
The idea is to share this repository with others in my company so they can use my functions. They would also be able to install my package dependencies from the local repository, which is faster than downloading them from CRAN and prevents proxy problems.
I'm using miniCRAN and drat for this.
Let's start from a simple example:
I created a new mytestpkg package in RStudio.
It contains only one R file (hello.R) that imports ggplot2:
#' Hello function
#'
#' @return NONE
#' @export
#' @import ggplot2
#'
#' @examples hello()
hello <- function() {
print("Hello, world!")
x <- seq(0, 10, by = 0.1)
y <- cos(x)
my.df <- data.frame(x, y)
ggplot(my.df, aes(x, y)) + geom_line() + geom_point()
}
I configured the project options so that ROxygen generates the NAMESPACE file. Here is what it contains:
# Generated by roxygen2: do not edit by hand
export(hello)
import(ggplot2)
Now I install the package in my repository:
require(miniCRAN)
# Generate the documentation and update the NAMESPACE file
devtools::document(roclets=c('rd', 'collate', 'namespace', 'vignette'))
# Build the package
package.source.path <- devtools::build()
# Insert the package in my local repo
drat::insertPackage(package.source.path,
repodir = "C:/path/to/my/repo",
action = "prune")
# Add my local repo to the list of repos
options(repos = c(CRAN = "https://ftp.igh.cnrs.fr/pub/CRAN/",
MyRepo = "file:///C:/path/to/my/repo"))
# Find dependencies
pkgs <- c("mytestpkg")
pkgList <- pkgDep(pkgs, type="source")
The problem here is that pkgList only contains one string:
> pkgList
[1] "mytestpkg"
So if I call makeRepo, it will only copy my package and not its dependencies.
What did I do wrong?
Edit:
Apparently, depPkg looks for imports that are in the DESCRIPTION file, not the NAMESPACE file.
So I need to manually edit the DESCRIPTION file each time I have a new import? That's inconvenient... Couldn't Roxygen do this?