Jacob Strunk
2016-Aug-18 22:12 UTC
[R] package.skeleton, environment argument causes error
Hello, I have been using package.skeleton from within an lapply statement
successfully (assuming good source code) with the following setup in the
past:
x=try(package.skeleton(package_name,path=pathi,code_files=file_i))
but now fails with error:
Error: evaluation nested too deeply: infinite recursion /
options(expressions=)?
I am working in RStudio Version 0.99.896, with 64 bit R version 3.3.1
(2016-06-21)
I have been probing the code for package.skeleton a bit and noticed that
the default arguments for 'list' and 'environment' are supplied
in the
function definition, thus making it impossible to achieve the conditions
envIsMissing=TRUE
missing(list) = TRUE
as a result of the fact that missing(list) cannot be true, the classesList
argument is empty and the call
classes0 <- .fixPackageFileNames(classesList)
then fails with the error
Error: evaluation nested too deeply: infinite recursion /
options(expressions=)?
If I remove the default arguments I get further, but get the same error I
had before (Error: evaluation nested too deeply: infinite recursion /
options(expressions=)?) after executing the following code:
methods0 <- .fixPackageFileNames(methodsList)
and the contents of methodsList look like
An object of class "ObjectsWithPackage":
Object:
Package:
the function .fixPackageFileNames fails when it reaches
list <- as.character(list)
where in this case the contents of 'list' look like
str(list)
Formal class 'ObjectsWithPackage' [package "methods"] with 2
slots
..@ .Data : chr(0)
..@ package: chr(0)
I am not sure if the problem arose from changes to package.skeleton
or methods::getClasses and methods::getGenerics or if there is something
peculiar about my environment.
my current ugly fix is to define the function .fixPackageFileNames in the
global environment and add a try statement and exit when it results in an
object of class "try-error":
.fixPackageFileNamesfunction (list)
{
list <- *try(*as.character(list)*)*
*if(class(list)=="try-error")return(list)*
if (length(list) == 0L)
return(list)
list0 <- gsub("[[:cntrl:]\"*/:<>?\\|]",
"_", list)
wrong <-
grep("^(con|prn|aux|clock\\$|nul|lpt[1-3]|com[1-4])(\\..*|)$",
list0)
if (length(wrong))
list0[wrong] <- paste0("zz", list0[wrong])
ok <- grepl("^[[:alnum:]]", list0)
if (any(!ok))
list0[!ok] <- paste0("z", list0[!ok])
list1 <- tolower(list0)
list2 <- make.unique(list1, sep = "_")
changed <- (list2 != list1)
list0[changed] <- list2[changed]
list0
}
Any assistance with this error would be greatly appreciated!
Thank you,
--
Jacob Strunk
strunky at gmail.com
[[alternative HTML version deleted]]
It would be helpful for us if you provide a reproducible examples when the current package.skeleton fails. Best, Uwe Ligges On 19.08.2016 00:12, Jacob Strunk wrote:> Hello, I have been using package.skeleton from within an lapply statement > successfully (assuming good source code) with the following setup in the > past: > > x=try(package.skeleton(package_name,path=pathi,code_files=file_i)) > > > but now fails with error: > > Error: evaluation nested too deeply: infinite recursion / > options(expressions=)? > > I am working in RStudio Version 0.99.896, with 64 bit R version 3.3.1 > (2016-06-21) > > > > > I have been probing the code for package.skeleton a bit and noticed that > the default arguments for 'list' and 'environment' are supplied in the > function definition, thus making it impossible to achieve the conditions > > envIsMissing=TRUE > missing(list) = TRUE > > > as a result of the fact that missing(list) cannot be true, the classesList > argument is empty and the call > > classes0 <- .fixPackageFileNames(classesList) > > > then fails with the error > > Error: evaluation nested too deeply: infinite recursion / > options(expressions=)? > > > If I remove the default arguments I get further, but get the same error I > had before (Error: evaluation nested too deeply: infinite recursion / > options(expressions=)?) after executing the following code: > > methods0 <- .fixPackageFileNames(methodsList) > > > and the contents of methodsList look like > > An object of class "ObjectsWithPackage": > > Object: > Package: > > > the function .fixPackageFileNames fails when it reaches > > list <- as.character(list) > > > where in this case the contents of 'list' look like > > str(list) > Formal class 'ObjectsWithPackage' [package "methods"] with 2 slots > ..@ .Data : chr(0) > ..@ package: chr(0) > > > I am not sure if the problem arose from changes to package.skeleton > or methods::getClasses and methods::getGenerics or if there is something > peculiar about my environment. > > my current ugly fix is to define the function .fixPackageFileNames in the > global environment and add a try statement and exit when it results in an > object of class "try-error": > > .fixPackageFileNames> function (list) > { > list <- *try(*as.character(list)*)* > *if(class(list)=="try-error")return(list)* > if (length(list) == 0L) > return(list) > list0 <- gsub("[[:cntrl:]\"*/:<>?\\|]", "_", list) > wrong <- grep("^(con|prn|aux|clock\\$|nul|lpt[1-3]|com[1-4])(\\..*|)$", > list0) > if (length(wrong)) > list0[wrong] <- paste0("zz", list0[wrong]) > ok <- grepl("^[[:alnum:]]", list0) > if (any(!ok)) > list0[!ok] <- paste0("z", list0[!ok]) > list1 <- tolower(list0) > list2 <- make.unique(list1, sep = "_") > changed <- (list2 != list1) > list0[changed] <- list2[changed] > list0 > } > > > Any assistance with this error would be greatly appreciated! > > Thank you, >