Skip to content

Commit

Permalink
Use withInvisible() to track visibility of expression
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-dranoel committed Jan 11, 2015
1 parent ec5dc2b commit b93075e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions R/swirl.R
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,21 @@ resume.default <- function(e, ...){
}
e$expr <- parse(text=correctAns)[[1]]
ce <- cleanEnv(e$snapshot)
e$val <- suppressMessages(suppressWarnings(eval(e$expr, ce)))
# evaluate e$expr keeping value and visibility information
# store the result in temporary object evaluation in order
# to avoid double potentially time consuming eval call
evaluation <- withVisible(eval(e$expr, ce))
e$vis <- evaluation$visible
e$val <- suppressMessages(suppressWarnings(evaluation$value))
xfer(ce, globalenv())
ce <- as.list(ce)

# Inform the user and expose the correct answer
swirl_out("Entering the following correct answer for you...",
skip_after=TRUE)
message("> ", e$current.row[, "CorrectAnswer"])
if(e$vis && !is.null(e$val)) {

if(e$vis & !is.null(e$val)) {
print(e$val)
}
}
Expand Down

0 comments on commit b93075e

Please sign in to comment.