From 226ff2bc87ea5ae57b25225ecb6e690198e79b87 Mon Sep 17 00:00:00 2001 From: Chris Baker Date: Thu, 13 Sep 2018 09:16:24 -0400 Subject: [PATCH] use different versions of file.edit depending on OS and IDE (closes #204) --- R/reprex.R | 2 +- R/utils.R | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/R/reprex.R b/R/reprex.R index 3940df1f..6301254a 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_edit2(reprex_file)) } } diff --git a/R/utils.R b/R/utils.R index bbc4aa1a..5a7ced8b 100644 --- a/R/utils.R +++ b/R/utils.R @@ -89,3 +89,15 @@ inject_file <- function(path, inject_path, pre_process = enfence, ...) { prose <- function(x) { paste0("#' ", x) } + +is_windows <- function() { + grepl("windows", Sys.info()[["sysname"]], ignore.case = TRUE) +} + +file_edit2 <- function(file) { + if (is_windows()) { + get("file.edit")(file) + } else { + utils::file.edit(file) + } +}