rrstudiophyloseq

How to display a dataframe with factors in R data viewer?


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?


Solution

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

    View(as.data.frame(a@.Data))