Patch the bug on aggregate when aggregating by samples

This commit is contained in:
2018-07-27 22:56:51 +02:00
parent fa77a5d041
commit baf1b1e6fc

View File

@@ -12,6 +12,7 @@ aggregate.metabarcoding.data=function(x, by, FUN,...,
default.layer=NULL, default.layer=NULL,
layers=NULL) { layers=NULL) {
uniq.value = function(z) { uniq.value = function(z) {
if (is.null(z) | if (is.null(z) |
@@ -57,10 +58,13 @@ aggregate.metabarcoding.data=function(x, by, FUN,...,
reads = x@reads reads = x@reads
if (MARGIN==1) { if (MARGIN==1) {
# prepare the aggrevation arguments for the read table # prepare the aggrevation arguments for the read table
# from the function arguments # from the function arguments
dotted = list(...) dotted = list(...)
if (length(dotted) > 0) if (length(dotted) > 0)
aggr.args = list(reads,by=by,FUN=FUN,...=dotted,simplify=FALSE) aggr.args = list(reads,by=by,FUN=FUN,...=dotted,simplify=FALSE)
else else
@@ -130,14 +134,15 @@ aggregate.metabarcoding.data=function(x, by, FUN,...,
# modalities to the last columns of the data.frame # modalities to the last columns of the data.frame
sagr = sagr[,c((ncat+1):(dim(sagr)[2]),1:ncat),drop=FALSE] sagr = sagr[,c((ncat+1):(dim(sagr)[2]),1:ncat),drop=FALSE]
larg = c(lapply(sagr,unlist),list(stringsAsFactors=FALSE)) larg = c(lapply(sagr,unlist),list(stringsAsFactors=FALSE))
sagr = do.call(data.frame,larg) sagr = data.frame(do.call(data.frame,larg))
# set samples ids to the ids computed from modalities # set samples ids to the ids computed from modalities
sagr$id=ids
rownames(sagr)=ids rownames(sagr)=ids
sagr$id=ids
# build the new metabarcoding data instance # build the new metabarcoding data instance
newdata = copy.metabarcoding.data(x,reads=ragr,samples=sagr) newdata = copy.metabarcoding.data(x,reads=ragr,samples=sagr,layers=la)
} }
else { else {