简体   繁体   中英

Code equivalent to 'broom' icon in viewer pane of RStudio?

To clear the viewer pane in RStudio, we can click on the 'broom' icon.

Is there a way to do this using R code?

Update: here's an example of how to render something random in the viewer pane (my question is how can we clear the viewer pane using code?)


sometext <- "<p>This text will render in the viewer pane</p>"

dir <- tempfile()
dir.create(dir)
TextFile <- file.path(dir, "TextFile.html")

writeLines(sometext, con = TextFile)
rstudioapi::viewer(TextFile) 

For anyone wondering, this works:

clear_viewer_pane <- function() {
  dir <- tempfile()
  dir.create(dir)
  TextFile <- file.path(dir, "blank.html")
  writeLines("", con = TextFile)
  rstudioapi::viewer(TextFile) 
}

clear_viewer_pane()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM