Skip to content

Instantly share code, notes, and snippets.

@timelyportfolio
Created February 2, 2015 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timelyportfolio/9e82ac7be40c070ae606 to your computer and use it in GitHub Desktop.
Save timelyportfolio/9e82ac7be40c070ae606 to your computer and use it in GitHub Desktop.
get all images from RStudio temp directory

RStudio achievement unlocked

Not sure if this might be useful to anyone but thought I would post it anyways. I thought it would be nice to be able to get all the images from the RStudio plots tab. On Windows, these are stored in tempdir(), so with some list.files, grepl, tag, and base64enc::dataURI, we could make an HTML page with all the charts. Where I think this will be most useful will be in an htmlwidget lightbox or something similar as an alternative and possibly more pleasant viewing experience.

library(htmltools)

html_print(lapply(
  list.files(tempdir(),"png",recursive=T,full.names=T)
  ,function(p){
    if(grepl(x=p,pattern="rs-graphics") && !(grepl(x=p,pattern="empty"))){
      tag("img",c(src=base64enc::dataURI(file=p)))
    }
  }
))
library(htmltools)
html_print(lapply(
list.files(tempdir(),"png",recursive=T,full.names=T)
,function(p){
if(grepl(x=p,pattern="rs-graphics") && !(grepl(x=p,pattern="empty"))){
tag("img",c(src=base64enc::dataURI(file=p)))
}
}
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment