Closed Aariq closed 1 year ago
Thanks. Seems like an oversight. Should be an easy fix, possibly just adding drop=FALSE
, but will need to do some testing before committing an update. For now, you could do something like this:
## Define tmp function
groupsTmp <- function(x, groups="fctgroup") {
if(class(x) != "SDFset") { stop("Input is not an 'SDFset' object") }
if(length(x) > 1) {
groups(x, groups)
} else if(length(x) == 1) {
matrix(groups(x, groups), nrow=1, dimnames=list(cid(x), names(groups(x, groups))))
} else {
stop("something unexpected")
}
}
## Test tmp function
library(ChemmineR)
data(sdfsample)
## More than 1 SDF
sdfset <- sdfsample
groupsTmp(x=sdfset)
## One SDF
sdfset <- sdfsample[1]
groupsTmp(x=sdfset)
groupsTmp(x=sdfset, groups="fctgroup")
groupsTmp(x=sdfset, groups="neighbors")
## Something unintended
sdfset <- iris
This has been fixed in version 3.53.1. Just needed a drop=FALSE
, as @tgirke suggested.
With an SDFset object with just 1 molecule, the output is a named numeric vector, otherwise it is a matrix. This makes it difficult to work with because the column names when converting the output to a data frame are different depending on the number of molecules in the SDFset.
Created on 2023-06-29 with reprex v2.0.2