[IRanges] Strange behaviour of global DataFrame with subset in function
1
0
Entering edit mode
@paul-theodor-pyl-5014
Last seen 10.2 years ago
Hi all, I have observed some strange behaviour when I use subset inside a function on a DataFrame that is a global variable, see the example below: > library(IRanges) # [...] > ir_df = DataFrame( x=rnorm(10) ) > old_df = as.data.frame( ir_df ) > a_function = function( cut_off ) subset( ir_df, x < cut_off ) > another_function = function( cut_off ) subset( old_df, x < cut_off ) > a_function( 0 ) Error in eval(expr, envir, enclos) : object 'cut_off' not found > another_function( 0 ) x 10 -0.750875 > sessionInfo() R version 2.15.2 (2012-10-26) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] 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 other attached packages: [1] IRanges_1.16.4 BiocGenerics_0.4.0 loaded via a namespace (and not attached): [1] parallel_2.15.2 stats4_2.15.2 As you can see this works with an old-style data.frame, but not with a new (CamelCase) one. I simply converted my DataFrame to a data.frame to fix it but I think it would be nice to know why that even happens in the first place?! Cheers, Paul
• 718 views
ADD COMMENT
0
Entering edit mode
@michael-lawrence-3846
Last seen 3.0 years ago
United States
Thanks, yes, I've hit this before but never took the time to solve it. The problem is that the methods package will sometimes (whenever we add formal arguments to a method definition where the generic has "...") inject the method body into a function called .local. The .local function is then called in the actual method body. This means that the stack is offset by one. So I went through all of the code in IRanges and found cases where we assumed parent.frame() would work but we end up inside a .local. Please try the latest devel. Michael On Thu, Nov 29, 2012 at 12:11 AM, Paul Theodor Pyl <paul.theodor.pyl@embl.de> wrote: > Hi all, > > I have observed some strange behaviour when I use subset inside a function > on a DataFrame that is a global variable, see the example below: > > > library(IRanges) > # [...] > > ir_df = DataFrame( x=rnorm(10) ) > > old_df = as.data.frame( ir_df ) > > a_function = function( cut_off ) subset( ir_df, x < cut_off ) > > another_function = function( cut_off ) subset( old_df, x < cut_off ) > > a_function( 0 ) > Error in eval(expr, envir, enclos) : object 'cut_off' not found > > another_function( 0 ) > x > 10 -0.750875 > > sessionInfo() > R version 2.15.2 (2012-10-26) > Platform: x86_64-unknown-linux-gnu (64-bit) > > locale: > [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C > [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 > [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 > [7] LC_PAPER=C LC_NAME=C > [9] 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 > > other attached packages: > [1] IRanges_1.16.4 BiocGenerics_0.4.0 > > loaded via a namespace (and not attached): > [1] parallel_2.15.2 stats4_2.15.2 > > As you can see this works with an old-style data.frame, but not with a new > (CamelCase) one. > > I simply converted my DataFrame to a data.frame to fix it but I think it > would be nice to know why that even happens in the first place?! > > Cheers, > Paul > > ______________________________**_________________ > Bioconductor mailing list > Bioconductor@r-project.org > https://stat.ethz.ch/mailman/**listinfo/bioconductor<https: stat.et="" hz.ch="" mailman="" listinfo="" bioconductor=""> > Search the archives: http://news.gmane.org/gmane.** > science.biology.informatics.**conductor<http: news.gmane.org="" gmane.="" science.biology.informatics.conductor=""> > [[alternative HTML version deleted]]
ADD COMMENT

Login before adding your answer.

Traffic: 554 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6