[R] package.skeleton, environment argument causes error

2016-08-18 Thread Jacob Strunk
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,

-- 
Jacob Strunk
stru...@gmail.com

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] problem with extract raster with polygon

2017-03-20 Thread Jacob Strunk
Hello, I am having some troubles extracting pixels from a raster using
polygons. When I attempt to do so, pixels which are only partially
intersected by polygons are not included.

In the example below the number of pixels returned is less than the number
of pixels which can be seen intersecting polygons.

As an aside I also encountered strange behavior in my example below after
buffering polygons by 10 units. After buffering polygons by 10 units, the
number of pixels return by extract was actually reduced.


Example
r <- raster(ncol=5, nrow=5)
r[] <- 1:ncell(r)

cds1 <- rbind(c(-180,-20), c(-160,5), c(-60, 0), c(-160,-70), c(-180,-20))
cds2 <- rbind(c(80,0), c(100,60), c(120,0), c(120,-55), c(80,0))
polys <- spPolygons(cds1, cds2)


plot(r)
plot(polys, add=TRUE)
plot(buffer(polys,10,dissolve=F), add=TRUE)
plot(buffer(polys,30,dissolve=F), add=TRUE)
plot(buffer(polys,100,dissolve=F), add=TRUE)

extract(r, polys)
extract(r, buffer(polys,10,dissolve=F))
extract(r, buffer(polys,30,dissolve=F))
extract(r, buffer(polys,100,dissolve=F))

my R output:
> extract(r, polys)
[[1]]
[1] 11 12 16

[[2]]
[1] 14  4 15 25

> extract(r, buffer(polys,10,dissolve=F))
[[1]]
[1] 11 12 16

[[2]]

14

> extract(r, buffer(polys,30,dissolve=F))
[[1]]
[1] 11 12 16 17 21

[[2]]
[1]  9 14 15 19 20 25

> extract(r, buffer(polys,100,dissolve=F))
[[1]]
 [1]  1  2  3  6  7  8 11 12 13 16 17 18 21 22 23

[[2]]
 [1]  3  4  5  8  9 10 13 14 15 18 19 20 24 25

> R.Version()
$platform
[1] "x86_64-w64-mingw32"

$arch
[1] "x86_64"

$os
[1] "mingw32"

$system
[1] "x86_64, mingw32"

$status
[1] ""

$major
[1] "3"

$minor
[1] "3.2"

$year
[1] "2016"

$month
[1] "10"

$day
[1] "31"

$`svn rev`
[1] "71607"

$language
[1] "R"

$version.string
[1] "R version 3.3.2 (2016-10-31)"

$nickname
[1] "Sincere Pumpkin Patch"



"Documentation for package ‘raster’ version 2.5-8" from Raster help pages


Thanks for any help

-- 
Jacob

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.