mikemc / speedyseq

Speedy versions of phyloseq functions
https://mikemc.github.io/speedyseq/
Other
45 stars 6 forks source link

`psmelt()` sometimes returns `Sample` variable as a factor #25

Closed mikemc closed 4 years ago

mikemc commented 4 years ago

Noticed while running phyloseq's psmelt tests

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(speedyseq)
#> Loading required package: phyloseq
#> 
#> Attaching package: 'speedyseq'
#> The following objects are masked from 'package:phyloseq':
#> 
#>     plot_bar, plot_heatmap, plot_tree, psmelt, tax_glom, tip_glom
data("GlobalPatterns")
GP <- prune_taxa(
  names(sort(taxa_sums(GlobalPatterns), TRUE)[1:50]), 
  GlobalPatterns
)
# The objects with NULL components
GPT <- phyloseq(otu_table(GP), tax_table(GP), phy_tree(GP))
test <- psmelt(GP)
testT <- psmelt(GPT)
test$Sample %>% head
#> [1] "AQC4cm"   "LMEpi24M" "AQC7cm"   "AQC1cm"   "M31Tong"  "M11Fcsw"
testT$Sample %>% head
#> [1] AQC4cm   LMEpi24M AQC7cm   AQC1cm   M31Tong  M11Fcsw 
#> 26 Levels: CL3 CC1 SV1 M31Fcsw M11Fcsw M31Plmr M11Plmr F21Plmr ... Even3

Created on 2020-03-13 by the reprex package (v0.3.0)

mikemc commented 4 years ago

This issue is caused by the call to data.table::melt(), and can be fixed by setting variable.factor = FALSE