From d1f8af3558a9a1d1e4a5c8d16b868bdc53603ea2 Mon Sep 17 00:00:00 2001 From: Alex Chubaty Date: Thu, 29 Oct 2015 11:50:06 -0700 Subject: [PATCH] temporary fix for #209 -- workaround bug in RStudio --- DESCRIPTION | 5 +++-- R/temp.R | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 R/temp.R diff --git a/DESCRIPTION b/DESCRIPTION index 26031683b..cf05af3ea 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -11,8 +11,8 @@ Description: Easily implement a variety of simulation models, with a focus on installed with `install.packages("fastshp", repos="http://rforge.net", type="source")`. URL: https://github.com/PredictiveEcology/SpaDES -Version: 1.0.3.9007 -Date: 2015-10-28 +Version: 1.0.3.9008 +Date: 2015-10-29 Authors@R: c( person(c("Alex", "M"), "Chubaty", email="alexander.chubaty@canada.ca", role=c("aut", "cre")), @@ -100,4 +100,5 @@ Collate: 'spades-package.R' 'splitRaster.R' 'spread-process.R' + 'temp.R' 'zzz.R' diff --git a/R/temp.R b/R/temp.R new file mode 100644 index 000000000..3f8e5f311 --- /dev/null +++ b/R/temp.R @@ -0,0 +1,44 @@ +### TEMPORARY FIX FOR ISSUE #209 -- FIXES RSTUDIO BUG +### https://github.com/achubaty/rstudio/commit/378ae10a29a3c6a0eb7680ff7f99d495b44aed9c +### pull request to come, pending copyright transfer agreement form + +options(editor = function(name, file, title) { + + # use internal editor for files and functions, otherwise + # delegate to the default editor + if (missing(name) || is.null(name) || is.function(name)) { + + # if no name then use file + if (missing(name) || is.null(name)) { + if (!is.null(file) && nzchar(file)) + targetFile <- file + else + targetFile <- scratchFile + } + # otherwise it's a function, write it to a file for editing + else { + functionSrc <- .rs.deparseFunction(name, TRUE, FALSE) + targetFile <- scratchFile + writeLines(functionSrc, targetFile) + } + + # invoke the RStudio editor on the file + if (.Call("rs_editFile", targetFile)) { + + # try to parse it back in + newFunc <- try(eval.parent(parse(targetFile)), + silent = TRUE) + if (inherits(newFunc, "try-error")) { + stop(newFunc, "You can attempt to correct the error using ", + title, " = edit()") + } + + return(newFunc) + } + else { + stop("Error occurred while editing function '", name, "'") + } + } + else + edit(name, file, title, editor=defaultEditor) +})