Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infinite loop of as.vector(x, mode) in default_usage.s4method #475

Closed
EricArcher opened this issue May 19, 2016 · 8 comments
Closed

infinite loop of as.vector(x, mode) in default_usage.s4method #475

EricArcher opened this issue May 19, 2016 · 8 comments

Comments

@EricArcher
Copy link

When I call roxygenise() on my package, I get the following error:

Error: C stack usage 7969260 is too close to the limit

After running traceback(), it appears an infinite loop is happening with as.vector(x, mode). I've used the results of traceback and debug to trace this back to a call to as.character(x$value@defined) that is being formed in roxygen2:::default_usage.s4method in the s4method function defined there, but actually called in roxygen2:::build_rd when the escape(eval(arg, env)) line is executed.

I have attached a zip file with .rdata files containing the result of
tb <- traceback()
and the object that causes the loop (x).

tb.and.x.zip

I can replicate this error by calling: as.character(x$value@defined)

Here is the result of str(x):

List of 3
$ alias : NULL
$ value :Formal class 'MethodDefinition' [package "methods"] with 4 slots
.. ..@ .Data :function (x, ...)
.. ..@ target :Formal class 'signature' [package "methods"] with 3 slots
.. .. .. ..@ .Data : chr "gtypes"
.. .. .. ..@ names : chr "x"
.. .. .. ..@ package: chr "roxygen_devtest"
.. ..@ defined:Formal class 'signature' [package "methods"] with 3 slots
.. .. .. ..@ .Data : chr "gtypes"
.. .. .. ..@ names : chr "x"
.. .. .. ..@ package: chr "roxygen_devtest"
.. ..@ generic: atomic [1:1] nInd
.. .. ..- attr(*, "package")= chr "adegenet"
$ methods: NULL

  • attr(*, "class")= chr [1:2] "s4method" "object"

and here is str(x$value@defined):

Formal class 'signature' [package "methods"] with 3 slots
..@ .Data : chr "gtypes"
..@ names : chr "x"
..@ package: chr "roxygen_devtest"

This has only started happening recently (in the past week) and I've been unable to work out what changes I've made in my package could be related to it. It initially occurred with the version of roxygen2 currently on CRAN, and I updated to the version from GitHub and had the same behavior.
I have not been able to work out which file is being parsed to produce this, but if you can tell me what clues I should use to look, I'm happy to do so to see if there is something wonky about the documentation.

My sessionInfo() is as follows:

R version 3.3.0 (2016-05-03)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.4 (El Capitan)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] swfscMisc_1.1.1 mapdata_2.2-6 maps_3.1.0
[4] reshape2_1.4.1 Rcpp_0.12.5 RColorBrewer_1.1-2
[7] pegas_0.9 Hmisc_3.17-4 Formula_1.2-1
[10] survival_2.39-4 lattice_0.20-33 ggplot2_2.1.0
[13] copula_0.999-14 adegenet_2.0.1 ade4_1.7-4
[16] apex_1.0.2 phangorn_2.0.3 ape_3.4
[19] roxygen2_5.0.1.9000

loaded via a namespace (and not attached):
[1] splines_3.3.0 gtools_3.5.0 shiny_0.13.2
[4] assertthat_0.1 sp_1.2-3 stats4_3.3.0
[7] latticeExtra_0.6-28 LearnBayes_2.15 quadprog_1.5-5
[10] chron_2.3-47 digest_0.6.9 polyclip_1.5-6
[13] colorspace_1.2-6 htmltools_0.3.5 httpuv_1.3.3
[16] Matrix_1.2-6 plyr_1.8.3 gmodels_2.16.2
[19] xtable_1.8-2 mvtnorm_1.0-5 scales_0.4.0
[22] gdata_2.17.0 tensor_1.5 ADGofTest_0.3
[25] mgcv_1.8-12 nnet_7.3-12 magrittr_1.5
[28] mime_0.4 deldir_0.1-12 nlme_3.1-128
[31] MASS_7.3-45 gsl_1.9-10.1 foreign_0.8-66
[34] tools_3.3.0 data.table_1.9.6 pspline_1.0-17
[37] stringr_1.0.0 munsell_0.4.3 cluster_2.0.4
[40] stabledist_0.7-0 grid_3.3.0 goftest_1.0-3
[43] igraph_1.0.1 boot_1.3-18 gtable_0.2.0
[46] abind_1.4-3 DBI_0.4-1 R6_2.1.2
[49] gridExtra_2.2.1 nnls_1.4 dplyr_0.4.3
[52] seqinr_3.1-3 fastmatch_1.0-4 spdep_0.6-4
[55] stringi_1.0-1 spatstat_1.45-2 parallel_3.3.0
[58] rpart_4.1-10 acepack_1.3-3.3 coda_0.18-1

@EricArcher
Copy link
Author

Update: I reverted back to R v3.2.3 and do not get the same error. This seems to be an issue with roxygen2 and R v. 3.3.0

@muschellij2
Copy link

muschellij2 commented Jun 27, 2016

Thought this was fixed with R v.3.3.1, but it was not.

@EricArcher
Copy link
Author

EricArcher commented Jun 27, 2016

I've narrowed the problem down even further. It seems to be due to an environment that gets associated with a method that roxygen2 creates when doing its magic. Something happens when this method definition with its associated environment is in the workspace that causes the error. As a test, I created a signature identical to the one that causes the error and tried the as.vector() command that would generate the loop seen above. I don't get the error in my command line generated object, nor with the object that is extracted from the method definition. However, when I load the method definition into the workspace, the error will happen on either my command line generated object, or the one extracted from the method definition and will not stop happening until I restart R.

Files are here: error test rdata files.zip

## Testing signature objects

Restarting R session...

> source('/Users/Shared/Work/R.Stuff/Packages/error test.R', echo=TRUE)

> rm(list = ls())

> # An in-code signature that is identical to the one leading to the error:
> test.sig <- new("signature", x = "gtypes")

> test.sig@package <- "roxygen_devtest"

> str(test.sig)
Formal class 'signature' [package "methods"] with 3 slots
  ..@ .Data  : chr "gtypes"
  ..@ names  : chr "x"
  ..@ package: chr "roxygen_devtest"

> # This is the signature that generates the error
> load("problem.sig.rdata")

> str(problem.sig)
Formal class 'signature' [package "methods"] with 3 slots
  ..@ .Data  : chr "gtypes"
  ..@ names  : chr "x"
  ..@ package: chr "roxygen_devtest"

> # Check that they are the same
> identical(test.sig, problem.sig)
[1] TRUE

> # The error/loop generating code for each (no error if fresh R session):
> as.vector(test.sig, "character")
[1] "gtypes"

> as.vector(problem.sig, "character")
[1] "gtypes"

> # Load method definition that signature came from:
> load("problem.method.rdata")

> str(problem.method)
Formal class 'MethodDefinition' [package "methods"] with 4 slots
  ..@ .Data  :function (x, ...)  
  ..@ target :Formal class 'signature' [package "methods"] with 3 slots
  .. .. ..@ .Data  : chr "gtypes"
  .. .. ..@ names  : chr "x"
  .. .. ..@ package: chr "roxygen_devtest"
  ..@ defined:Formal class 'signature' [package "methods"] with 3 slots
  .. .. ..@ .Data  : chr "gtypes"
  .. .. ..@ names  : chr "x"
  .. .. ..@ package: chr "roxygen_devtest"
  ..@ generic: atomic [1:1] nInd
  .. ..- attr(*, "package")= chr "adegenet"

> str(problem.method@defined)
Formal class 'signature' [package "methods"] with 3 slots
  ..@ .Data  : chr "gtypes"
  ..@ names  : chr "x"
  ..@ package: chr "roxygen_devtest"

> # Check that problem signature in problem.method@defined is same as test signature above:
> identical(problem.method@defined, test.sig)
[1] TRUE

> # Both of these now generate error (only change is that problem method has been loaded into workspace):
> as.vector(test.sig, "character")
Error: C stack usage  7969436 is too close to the limit
> as.vector(problem.method@defined, "character")
Error: C stack usage  7970892 is too close to the limit

I then confirmed what it was in the method definition by creating one that was close to the one causing the error, then swapping parts from each until the error stopped happening. It turns out that it is the environment defined in the @.Data slot:

## Testing method definition:

Restarting R session...

> rm(list = ls())
> 
> # Create test class and method
> setClass(Class = "gtypes", slots = c(loci = "data.frame", ploidy = "numeric"), package = "roxygen_devtest")
> setGeneric("nInd", function(x, ...) standardGeneric("nInd"), package = "adegenet")
[1] "nInd"
> setMethod("nInd", "gtypes", function(x, ...) nrow(x@loci) / x@ploidy)
[1] "nInd"
> 
> test.method <- getMethod("nInd", "gtypes")
> str(test.method)
Formal class 'MethodDefinition' [package "methods"] with 4 slots
  ..@ .Data  :function (x, ...)  
  ..@ target :Formal class 'signature' [package "methods"] with 3 slots
  .. .. ..@ .Data  : chr "gtypes"
  .. .. ..@ names  : chr "x"
  .. .. ..@ package: chr "roxygen_devtest"
  ..@ defined:Formal class 'signature' [package "methods"] with 3 slots
  .. .. ..@ .Data  : chr "gtypes"
  .. .. ..@ names  : chr "x"
  .. .. ..@ package: chr "roxygen_devtest"
  ..@ generic: atomic [1:1] nInd
  .. ..- attr(*, "package")= chr "adegenet"
> 
> # No error:
> as.vector(test.method@defined, "character")
[1] "gtypes"
> 
> # This is the method that generates the error
> load("problem.method.rdata")
> 
> # Notice the difference in the environments of the two functions:
> test.method@.Data
function (x, ...) 
nrow(x@loci)/x@ploidy
> problem.method@.Data
function (x, ...) 
nrow(x@loci)/x@ploidy
<environment: 0x101f85040>
> 
> # Swap the problem function for the one I created:
> problem.method@.Data <- test.method@.Data
> save(problem.method, file = "fixed.method.rdata")
> 
> # Here's the error (both with my method and the original):
> as.vector(test.method@defined, "character")
Error: C stack usage  7970892 is too close to the limit
> as.vector(problem.method@defined, "character")
Error: C stack usage  7970892 is too close to the limit

Restarting R session...

> # *** Restart R for this to work ***
> rm(list = ls())
> 
> load("fixed.method.rdata")
> as.vector(problem.method@defined, "character")
[1] "gtypes"

@kevinushey
Copy link
Contributor

I wonder if this should be posted on R-devel? I noticed a similar issue with loading of S4 objects; it appears that the class definitions are sometimes not materialized correctly.

@EricArcher
Copy link
Author

I've been thinking the same thing. I posted it to r-help a few days ago but just got crickets. I was waiting until the end of the week to re-post to r-devel.

@EricArcher
Copy link
Author

Based on a suggestion by Luke Tierney, I removed packages one-by-one to see if I could make the error go away with that. When I removed Matrix (v1.2-6 on R 3.3.1), I got no error. Matrix automatically reinstalls (same version), but all is good now.

@muschellij2
Copy link

muschellij2 commented Jul 7, 2016

Reinstalled all package dependencies and roxygen worked. Thanks for the help.

@sylvainschmitt
Copy link

Hello, I tried reinstalling all package dependencies and roxygen2 multiple times and in different ways and I still got the issue. Any precisions about what you exactly did and how ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants