gdkrmr / dimRed

A Framework for Dimensionality Reduction in R
https://www.guido-kraemer.com/software/dimred/
GNU General Public License v3.0
73 stars 15 forks source link

Argument `.keep.org.data` not working #56

Open FinYang opened 2 years ago

FinYang commented 2 years ago

Hi there,

Please see below the repro. The examples are taken from documentation of embed.

library(dimRed)
#> Loading required package: DRR
#> Loading required package: kernlab
#> Loading required package: CVST
#> Loading required package: Matrix
#> 
#> Attaching package: 'dimRed'
#> The following object is masked from 'package:stats':
#> 
#>     embed
#> The following object is masked from 'package:base':
#> 
#>     as.data.frame

as.data.frame(
  embed(Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width,
        iris, "PCA", .keep.org.data = FALSE)
)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'as.data.frame': invalid class "dimRedResult" object: invalid object for slot "org.data" in class "dimRedResult": got class "NULL", should be or extend class "matrix"

as.data.frame(embed(iris[, 1:4], "PCA", .keep.org.data = FALSE))
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'as.data.frame': invalid class "dimRedResult" object: invalid object for slot "org.data" in class "dimRedResult": got class "NULL", should be or extend class "matrix"

Created on 2022-08-28 by the reprex package (v2.0.1)

gdkrmr commented 2 years ago

I can confirm it, thanks for reporting!

FYI: it keeps the original data if you omit .keep.org.data.

gdkrmr commented 2 years ago

in dimRedResults-class, the slot org.data can only be of class matrix, so I cannot just use a NULL. Should getOrgData and getData return a 0-column matrix silently or throw an error or a warning if the original data is not saved?