Guest User

Untitled

a guest
Jan 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. # Imagine I have a local data.frame/object I am interested in plotting to html via render
  2. iris_revised <- iris
  3.  
  4. # My current workflow is to save this object
  5. save(iris_revised, file = 'data/iris_revised.Rdata')
  6.  
  7. # And then call another script via the render function
  8. rmarkdown::render('R/plot_iris_revised.R', output_format = 'html_document')
  9.  
  10. library(ggplot2)
  11. load('../data/iris_revised.Rdata')
  12.  
  13. for(Species in levels(iris_revised$Species)){
  14. cat('#', Species, 'n')
  15. p <- ggplot(iris_revised[iris_revised$Species == Species,], aes(x =
  16. Sepal.Length, y = Sepal.Width)) +
  17. geom_point()
  18. print(p)
  19. }
  20.  
  21. # Ideally I could just do something like this, where I could just render html in the same workflow
  22. input_text <- "
  23. for(Species in levels(iris_revised$Species)){
  24. cat('#', Species, 'n')
  25. p <- ggplot(iris_revised[iris_revised$Species == Species,], aes(x =
  26. Sepal.Length, y = Sepal.Width)) +
  27. geom_point()
  28. print(p)
  29. }
  30. "
  31. rmarkdown::render(input_text, output_format = 'html_document')
Add Comment
Please, Sign In to add comment