Transform class inside packet

1

I have an array and I want to transform it into another specific class of a package, rgeos , I put @import into the package, I give library to it too, but when I check this error, p>

a = matrix(1, 2,2)
as(a, "gpc.poly")
Error in as(x, "gpc.poly"): no method or default for coercing "matrix" to "gpc.poly"

How to solve?

Q. I have read Hadley and the R packages book, but I have succeeded.

    
asked by anonymous 29.06.2016 / 22:36

1 answer

1

The following roxygen2 header imports the method you need:

#' Hello
#' @export
#' @importFrom rgeos coerce
hello <- function() {
  a = matrix(1, 2,2)
  as(a, "gpc.poly")
}

This is a bit strange: for the as function to function correctly needs the function coerce of the rgeos package. Remember that the package must be correctly installed.

The package build returned this:

==> devtools::document(roclets=c('rd', 'collate', 'namespace'))

Updating test documentation
Loading test
Writing NAMESPACE
Documentation completed

==> R CMD INSTALL --no-multiarch --with-keep.source test

* installing to library ‘/home/dfalbel/R/x86_64-pc-linux-gnu-library/3.2’
* installing *source* package ‘test’ ...
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (test)

And the function worked correctly:

Restarting R session...

> library(test)
> hello()
GPC Polygon
   Num. Contours:  1 
   Num. Vertices:  2 
   BBox (X):  1 --> 1 
   BBox (Y):  1 --> 1 
    
30.06.2016 / 01:27