[BioC] [IRanges] Strange behaviour of global DataFrame with subset in function

Paul Theodor Pyl paul.theodor.pyl at embl.de
Thu Nov 29 09:11:46 CET 2012


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



More information about the Bioconductor mailing list