@@ -33,15 +33,12 @@ r$run(function() {
3333 dev.control(displaylist = " enable" )
3434 },
3535 viewer = function (url , ... ) {
36- write_log(" viewer: " , url )
3736 viewer_file <<- url
3837 },
3938 page_viewer = function (url , ... ) {
40- write_log(" page_viewer: " , url )
4139 viewer_file <<- url
4240 },
4341 browser = function (url , ... ) {
44- write_log(" browser: " , url )
4542 browser_url <<- url
4643 }
4744 )
@@ -52,7 +49,9 @@ r$run(function() {
5249 }
5350
5451 evaluate <- function (id , uri , expr ) {
55- tryCatch({
52+ viewer_file <<- NULL
53+ browser_url <<- NULL
54+ res <- tryCatch({
5655 expr <- parse(text = expr )
5756 out <- withVisible(eval(expr , globalenv()))
5857 text <- utils :: capture.output(print(out $ value , view = TRUE ))
@@ -62,33 +61,33 @@ r$run(function() {
6261 svglite :: svglite(plot_file , width = 12 , height = 8 )
6362 replayPlot(record )
6463 graphics.off()
65- res <- list (
64+ list (
6665 type = " plot" ,
6766 result = plot_file
6867 )
6968 } else if (! is.null(viewer_file )) {
70- res <- list (
69+ list (
7170 type = " viewer" ,
7271 result = viewer_file
7372 )
7473 } else if (! is.null(browser_url )) {
75- res <- list (
74+ list (
7675 type = " browser" ,
7776 result = browser_url
7877 )
7978 } else if (out $ visible ) {
80- res <- list (
79+ list (
8180 type = " text" ,
8281 result = paste0(text , collapse = " \n " )
8382 )
8483 } else {
85- res <- list (
84+ list (
8685 type = " text" ,
8786 result = " "
8887 )
8988 }
9089 }, error = function (e ) {
91- res <- list (
90+ list (
9291 type = " error" ,
9392 result = conditionMessage(e )
9493 )
0 commit comments