Is there a way to display multiple tables in the RStudio Viewer?

Viewed 1637

If I run the following crosstab code, using the ctable function from the summarytools package:

library(summarytools)
data(mtcars)
varlist <- names(mtcars[,3:5])
crosstables <- list(NULL)
for (i in varlist){
  crosstables[[i]] <- ctable(mtcars[[i]], mtcars$cyl, prop = 'r', style="simple", method = "render", header=TRUE)
  view(crosstables[[i]])
  }

instead of seeing three crosstab tables in the RStudio viewer only the last one is displayed. If I attempt to display all three tables:

view(crosstables)

I get the following error message:

x must either be a summarytools object created with freq(), descr(), or a list of freq() / descr() objects created using by(), or a list of freq() objects created using lapply(). Support for by() used with ctable() may be available in future realeases.

Is there a way to stack all three tables in the same viewer window? Maybe a way to combine the html output files for the crosstabs?

2 Answers

you can change view to print and knit to html

It's the same code:

library(summarytools)
data(mtcars)
varlist <- names(mtcars[,3:5])
crosstables <- list(NULL)
for (i in varlist){
  crosstables[[i]] <- ctable(mtcars[[i]], mtcars$cyl, prop = 'r', style="simple", method = "render", header=TRUE)
  print(crosstables[[i]])
  }

Only the last line is different. And then use RStudio's knitting feature:

enter image description here

As an alternative to the markdown solution, there is an append parameter to the package's print method / view functions. So when you use the file parameter and direct outputs from your first cross-table to an html file, you can use the same file path for the 2 other ones using append=TRUE.

Related