Basil Abou El-Komboz
2012-Sep-11 14:53 UTC
[Rd] R crashes when printing a named numeric vector of a specific class - Bug?
Dear useR's, today I stumbled over an interesting phenomenon: First, I created a named numeric vector with a certain class and several attributes via the structure() function. After that, I implemented a simple print method for this class. When calling this function it produces an endless loop of print calls until R crashes. :/ What is going on here? Is this a bug or have I done something completely wrong? :) Below is a minimal example which reproduces the behavior. Be careful when calling foo() as this automatically calls print.bar() which causes R to crash (at least on my PC, see further informations about my system below.) Greetings, Basil -------------------------------------------------- Minimal example: foo <- function () { x <- c("A" = 1.3, "B" = 0.7, "C" = -0.3) structure(x, class = "bar") } print.bar <- function (x, ...) { print(x, ...) } -------------------------------------------------- Further informations about my system:> version_ platform x86_64-unknown-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 15.1 year 2012 month 06 day 22 svn rev 59600 language R version.string R version 2.15.1 (2012-06-22) nickname Roasted Marshmallows> sessionInfo()R version 2.15.1 (2012-06-22) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 [6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=C LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] compiler_2.15.1 tools_2.15.1
Jeff Ryan
2012-Sep-11 15:30 UTC
[Rd] R crashes when printing a named numeric vector of a specific class - Bug?
print(x) in print.bar is calling print.bar again. You need to do something like print(unclass(x)) HTH Jeff On Tue, Sep 11, 2012 at 9:53 AM, Basil Abou El-Komboz <Basil.Abou-El-Komboz at stat.uni-muenchen.de> wrote:> Dear useR's, > > today I stumbled over an interesting phenomenon: First, I created a > named numeric vector with a certain class and several attributes via the > structure() function. After that, I implemented a simple print method > for this class. When calling this function it produces an endless loop > of print calls until R crashes. :/ > > What is going on here? Is this a bug or have I done something completely > wrong? :) > > Below is a minimal example which reproduces the behavior. Be careful > when calling foo() as this automatically calls print.bar() which causes > R to crash (at least on my PC, see further informations about my system below.) > > Greetings, > Basil > > -------------------------------------------------- > > Minimal example: > > foo <- function () { > x <- c("A" = 1.3, "B" = 0.7, "C" = -0.3) > structure(x, class = "bar") > } > > print.bar <- function (x, ...) { > print(x, ...) > } > > -------------------------------------------------- > > Further informations about my system: > >> version > _ > platform x86_64-unknown-linux-gnu > arch x86_64 > os linux-gnu > system x86_64, linux-gnu > status > major 2 > minor 15.1 > year 2012 > month 06 > day 22 > svn rev 59600 > language R > version.string R version 2.15.1 (2012-06-22) > nickname Roasted Marshmallows > >> sessionInfo() > > R version 2.15.1 (2012-06-22) > Platform: x86_64-unknown-linux-gnu (64-bit) > > locale: > [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 > [6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=C LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C > [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > loaded via a namespace (and not attached): > [1] compiler_2.15.1 tools_2.15.1 > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel-- Jeffrey Ryan jeffrey.ryan at lemnica.com www.lemnica.com
Milan Bouchet-Valat
2012-Sep-11 15:35 UTC
[Rd] R crashes when printing a named numeric vector of a specific class - Bug?
Le mardi 11 septembre 2012 ? 16:53 +0200, Basil Abou El-Komboz a ?crit :> Dear useR's, > > today I stumbled over an interesting phenomenon: First, I created a > named numeric vector with a certain class and several attributes via the > structure() function. After that, I implemented a simple print method > for this class. When calling this function it produces an endless loop > of print calls until R crashes. :/ > > What is going on here? Is this a bug or have I done something completely > wrong? :) > > Below is a minimal example which reproduces the behavior. Be careful > when calling foo() as this automatically calls print.bar() which causes > R to crash (at least on my PC, see further informations about my system below.) > > Greetings, > Basil > > -------------------------------------------------- > > Minimal example: > > foo <- function () { > x <- c("A" = 1.3, "B" = 0.7, "C" = -0.3) > structure(x, class = "bar") > } > > print.bar <- function (x, ...) { > print(x, ...) > }What is your code supposed to do exactly? ;-) You're calling print() in your class' print.bar() function, so calling print() on such an object will call print.bar(), which calls print(), which calls print.bar()... In a few moments the recursion will have gone so deep that some system limit about the stack size must be reached, and R is killed. If you just want to print the object as a vector, you do not need to define any function. Or, at least, call print.default() instead of the generic print(). My two cents> -------------------------------------------------- > > Further informations about my system: > > > version > _ > platform x86_64-unknown-linux-gnu > arch x86_64 > os linux-gnu > system x86_64, linux-gnu > status > major 2 > minor 15.1 > year 2012 > month 06 > day 22 > svn rev 59600 > language R > version.string R version 2.15.1 (2012-06-22) > nickname Roasted Marshmallows > > > sessionInfo() > > R version 2.15.1 (2012-06-22) > Platform: x86_64-unknown-linux-gnu (64-bit) > > locale: > [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 > [6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=C LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C > [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > loaded via a namespace (and not attached): > [1] compiler_2.15.1 tools_2.15.1 > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
Henrik Bengtsson
2012-Sep-11 23:57 UTC
[Rd] R crashes when printing a named numeric vector of a specific class - Bug?
For whoever is going to troubleshoot this, I cannot reproduce this endless-loop crash on Windows (Platform: x86_64-w64-mingw32/x64 (64-bit)). With:> foo <- function () {+ x <- c("A" = 1.3, "B" = 0.7, "C" = -0.3) + structure(x, class = "bar") + }> > print.bar <- function (x, ...) {+ print(x, ...) + } I get:> foo()Error: C stack usage is too close to the limit on R version 2.14.2 (2012-02-29) and R version 2.15.1 Patched (2012-09-10 r60659), and> foo()Error: evaluation nested too deeply: infinite recursion / options(expressions=)? on R Under development (unstable) (2012-09-10 r60659) /Henrik On Tue, Sep 11, 2012 at 7:53 AM, Basil Abou El-Komboz <Basil.Abou-El-Komboz at stat.uni-muenchen.de> wrote:> Dear useR's, > > today I stumbled over an interesting phenomenon: First, I created a > named numeric vector with a certain class and several attributes via the > structure() function. After that, I implemented a simple print method > for this class. When calling this function it produces an endless loop > of print calls until R crashes. :/ > > What is going on here? Is this a bug or have I done something completely > wrong? :) > > Below is a minimal example which reproduces the behavior. Be careful > when calling foo() as this automatically calls print.bar() which causes > R to crash (at least on my PC, see further informations about my system below.) > > Greetings, > Basil > > -------------------------------------------------- > > Minimal example: > > foo <- function () { > x <- c("A" = 1.3, "B" = 0.7, "C" = -0.3) > structure(x, class = "bar") > } > > print.bar <- function (x, ...) { > print(x, ...) > } > > -------------------------------------------------- > > Further informations about my system: > >> version > _ > platform x86_64-unknown-linux-gnu > arch x86_64 > os linux-gnu > system x86_64, linux-gnu > status > major 2 > minor 15.1 > year 2012 > month 06 > day 22 > svn rev 59600 > language R > version.string R version 2.15.1 (2012-06-22) > nickname Roasted Marshmallows > >> sessionInfo() > > R version 2.15.1 (2012-06-22) > Platform: x86_64-unknown-linux-gnu (64-bit) > > locale: > [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 > [6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=C LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C > [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > loaded via a namespace (and not attached): > [1] compiler_2.15.1 tools_2.15.1 > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
Maybe Matching Threads
- Big Data reading subsample csv
- How are R version types named ? Any convention (like Hurricanes etc)
- Behavior or as.environment in function arguments/call (and force() behaviors...)
- problem building vignette
- Windows 7 R (32/64bit) running under cygwin: package not found