-1

I'm working with sjPlot in order to get "pretty" tables. I managed to create a really nice contingency and another table providing me with frequencies of a variable.

Everything is just nice and the way it should be - except for one thing: I work with RStudio and when I run my code that includes several sjPlot-tables as output, I can only access the latest one. Unlike the graphics-window of RStudio, where you can click back and forth through your output, I'm stuck here with just the last table.

Is there a way to create a new tab or window or so, that I can run my code and get access to all the tables I created?

That would be super cool!

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
RJW
  • 13
  • 1
  • 1
  • 5

2 Answers2

0

Currently, there is no history feature for the Viewer pane in RStudio. You may open the tables in your browser instead (or additional, there's an icon in the Viewer pane), so you have multiple browser tabs, each with a table output.

Or you "concat" multiple tables and show them in the Viewer pane, however, this is quite an effort to do.

# create and save first HTML-table
part1 <- sjt.lm(fit1, fit2)
# create and save second HTML-table
part2 <- sjt.lm(fit3, fit4)
# browse temporary file
htmlFile <- tempfile(fileext=".html")
write(sprintf("<html><head>%s</head><body>%s<p></p>%s</body></html>",
              part1$page.style,
              part1$page.content,
              part2$page.content),
      file = htmlFile)
viewer <- getOption("viewer")
if (!is.null(viewer)) viewer(htmlFile) else     
utils::browseURL(htmlFile)
Daniel
  • 7,252
  • 6
  • 26
  • 38
0

Thanks Daniel! That actually really helps a lot!

I also figured out (which is why I'm posting this as an answer and not just as a comment...) that windows() also creates new data windows through RStudio. This might be interesting to other RStudio users as well :-)

Here's some example code just quickly copied out of my script:

scatter <- ggplot(na.action=na.exclude, spending.analysis, aes(age, money))
windows()
scatter + 
        geom_point(aes(color = school), alpha = 0.7) +
        geom_smooth( method = "lm", color = "dark blue", alpha = 0.05, fill = "blue", na.action = na.exclude) +
        facet_grid(. ~ school) +
        theme_bw() +
        scale_color_manual(values = group.colors)

I think this explains where to put the windows() command

RJW
  • 13
  • 1
  • 1
  • 5