0

I have a class that contains a dataframe where the columns are factors (from package phyloseq). It looks like that:

> str(a)
'data.frame':   124 obs. of  21 variables:
Formal class 'sample_data' [package "phyloseq"] with 4 slots
  ..@ .Data    :List of 21
  .. ..$ : Factor w/ 2 levels "L25","L53": 2 2 2 2 2 2 2 2 1 1 ...
  .. ..$ : Factor w/ 1 level "feces metagenome": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ : Factor w/ 1 level "none": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ : Factor w/ 1 level "not applicable": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ : Factor w/ 1 level "not applicable": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ : Factor w/ 1 level "feces": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ : Factor w/ 2 levels "Germany:Berlin",..: 2 2 2 2 2 2 2 2 1 1 ...
  .. ..$ : Factor w/ 1 level "Mus musculus": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ : Factor w/ 1 level "not applicable": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ : Factor w/ 1 level "none": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ : Factor w/ 1 level "none": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ : Factor w/ 1 level "none": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ : Factor w/ 3 levels "female","male",..: 1 1 1 1 2 2 1 1 3 3 ...

  ..@ names    : chr  "Library" "Organism" "Collection_date" "Env_biome" ...
  ..@ row.names: chr  "285L53" "286L53" "287L53" "288L53" ...
  ..@ .S3Class : chr "data.frame"

I can view the data in the console without problem but would like to inspect it in the data viewer. However, if I try to do that I only get a table that shows the column names, type of the column, which is "factor", and the levels of said factor, like this

Name       Type                               Value
a          List[124x21(phyloseq::sample_data) A data.frame with 124 rows and 21 columns
 Library   factor                             Factor with 2 levels "L25", "L53"
 Organism  factor                             Factor with 1 level: "feces Metagenome"
 etc.

I am somewhat new to R and have tried the following:

View(a@.Data)
View(a)
View(a@.Data[])

I suspect I lack some knowledge in S4 classes and their syntax, can you give me a hint how I display the actual data in Data viewer?

  • I'm pretty sure that the issue is not that there are factors, but that it is S4 shenanigans. – Axeman Feb 05 '20 at 15:28

1 Answers1

0

Firstly try to change the object to dataframe and then apply View function

View(as.data.frame(a@.Data))
norimg
  • 96
  • 3
  • OK, that worked! Also my column names are now something like "structure.c.2L..2L..2L..2L..2L..2L..2L..2L..1L..1L..1L..1L..1L.." But I guess I can handle that. – Sepp Hauser Feb 06 '20 at 07:44
  • great! add argument "col.names = [colnames]" to the function: like View(as.data.frame(a@.Data), col.names =c("a","b","c")) would be happy if you mark my answer as solution! – norimg Feb 06 '20 at 08:40