From f3f3a9d67dcb180ca233831ff0da61c3a2c24ed9 Mon Sep 17 00:00:00 2001 From: Chris Baker Date: Mon, 17 Sep 2018 17:22:40 -0400 Subject: [PATCH] use different version of file.edit depending on context (closes #204) --- R/reprex.R | 2 +- R/utils.R | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/R/reprex.R b/R/reprex.R index 7a24a11a..2df525d3 100644 --- a/R/reprex.R +++ b/R/reprex.R @@ -374,7 +374,7 @@ reprex <- function(x = NULL, " * ", reprex_file ) if (yep("Open the output file for manual copy?")) { - withr::defer(utils::file.edit(reprex_file)) + withr::defer(file_edit(reprex_file)) } } diff --git a/R/utils.R b/R/utils.R index ee580b8b..e6ea27a0 100644 --- a/R/utils.R +++ b/R/utils.R @@ -97,3 +97,11 @@ collapse <- function(x, sep = "\n") { backtick <- function(x) encodeString(x, quote = "`") newline <- function(x) paste0(x, "\n") + +file_edit <- function(...) { + if (exists("file.edit", envir = globalenv())) { + get("file.edit", envir = globalenv())(...) + } else { + utils::file.edit(...) + } +}