I have committed a fix for this (to be version 1.17.28). We now have an "ANY" coerce method for DataFrame. Just pushed up the coercion for Vector/vector (which were somehow separate but did the exact same coercion). Also had to fix a bug in showAsCell so that things are printed. Using I() is no longer required for these sparse vectors.
Michael On Tue, Jan 22, 2013 at 5:17 AM, Tim Yates <tya...@picr.man.ac.uk> wrote: > I believe you have to wrap objects in the I() function to stop DataFrame > trying to coerce your parameters to a DataFrame > > > y <- as(c(1,0,1,0,1,0),"sparseVector") > > a = DataFrame(spvec = I( y ) ) > > a[,1] > sparse vector (nnz/length = 3/6) of class "dsparseVector" > [1] 1 . 1 . 1 . > > > However, you can't display the variable 'a', as it again tries to coerce > it and fails: > > > a > DataFrame with 6 rows and 1 column > Error in as.matrix(format(as.data.frame(lapply(object, showAsCell), > optional = TRUE))) : > error in evaluating the argument 'x' in selecting a method for function > 'as.matrix': Error in as.data.frame.default(x[[i]], optional = TRUE) : > cannot coerce class '"dsparseVector"' into a data.frame > > > Tim > > On 22/01/2013 10:02, "Michael Love" <l...@molgen.mpg.de> wrote: > > >hi all, > > > >I am having trouble putting sparse vectors as columns of a DataFrame. > >They have 'length' and '[' methods: > > > > > library(Matrix) > > > library(IRanges) > > > y <- as(c(1,0,1,0,1,0),"sparseVector") > > > y > >sparse vector (nnz/length = 3/6) of class "dsparseVector" > >[1] 1 . 1 . 1 . > > > y[6] > >sparse vector (nnz/length = 0/1) of class "dsparseVector" > >[1] . > > > length(y) > >[1] 6 > > > DataFrame(spvec = y) > >Error in DataFrame(spvec = y) : > > cannot coerce class "dsparseVector" to a DataFrame > > > > > sessionInfo() > >R Under development (unstable) (2012-10-31 r61057) > >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] parallel stats graphics grDevices utils datasets methods > >[8] base > > > >other attached packages: > >[1] IRanges_1.17.26 BiocGenerics_0.5.6 Matrix_1.0-10 > >[4] lattice_0.20-13 Defaults_1.1-1 BiocInstaller_1.9.6 > > > >loaded via a namespace (and not attached): > >[1] grid_2.16.0 stats4_2.16.0 tools_2.16.0 > > > > > >thanks! > > > >Mike > > > >_______________________________________________ > >Bioc-devel@r-project.org mailing list > >https://stat.ethz.ch/mailman/listinfo/bioc-devel > > ________________________________ > > > This email is confidential and intended solely for the...{{dropped:10}} _______________________________________________ Bioc-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/bioc-devel