[Rd] R CMD build errors if files cannot be moved, even if they are in Rbuildignore

Hugh Parsonage hugh.parsonage at gmail.com
Fri Sep 22 02:14:24 CEST 2017


When a package is built it is first moved to a temporary directory (lines
962-980 in build.R). However, this moves *all* files to the temporary
directory, even those in Rbuildignore; only later (lines 997-1024) are
Rbuildignore files excluded.

The problem with this approach is that some files in the package directory
may not be movable. On Windows at least, the full path name to a file must
not be overly long (around 250 chars). Attempting to copy such files using
`file.copy` is a warning, and ultimately fails. In particular, if a package
uses a `data-raw` folder to prepare data, and data-raw/ contains such long
files, R CMD build will not work, meaning that the data-raw folder has to
be manually stashed before building.

I propose that the following line

if (!file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE))

should be replaced by something like the following

include <- allfiles[!inRbuildignore(allfiles, pkgdir)] # possibly the rest
of the exclude conds too
mov2Tdir <- function(x) {
file.copy(x, file.path(Tdir, x), copy.date = TRUE)
}
if (any(!vapply(include, mov2Tdir, FUN.VALUE = logical(1))))

This change would preserve the error condition, but not erroneously when
failing to copy files which will never be built.
This may or may not make the unlink(allfiles[exclude], recursive = TRUE,
force = TRUE) line redundant; I'm not sure.


Hugh Parsonage
Grattan Institute.

	[[alternative HTML version deleted]]



More information about the R-devel mailing list