Skip to content

Commit 523a59b

Browse files
committed
Bring back fileEdit to open files properly in RStudio
1 parent ec1ee1b commit 523a59b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

R/scaffold_utils.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
21
slurp <- function(file) {
32
paste(readLines(
43
system.file(file, package = 'reactR')
54
), collapse = "\n")
65
}
76

7+
# invoke file.edit in a way that will bind to the RStudio editor
8+
# when running inside RStudio
9+
fileEdit <- function(file) {
10+
fileEditFunc <- eval(parse(text = "file.edit"), envir = globalenv())
11+
fileEditFunc(file)
12+
}
13+
814
# Perform a series of pattern replacements on str.
915
# Example: renderTemplate("foo ${x} bar ${y} baz ${x}", list(x = 1, y = 2))
1016
# Produces: "foo 1 bar 2 baz 1"

R/scaffold_widget.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ addWidgetConstructor <- function(name, package, edit){
5252
capName = capitalize(name)
5353
)
5454
)
55-
if (edit) utils::file.edit(file)
55+
if (edit) fileEdit(file)
5656
}
5757

5858
addWidgetYAML <- function(name, edit){
@@ -61,7 +61,7 @@ addWidgetYAML <- function(name, edit){
6161
"templates/widget_yaml.txt",
6262
"boilerplate for widget dependencies"
6363
)
64-
if (edit) utils::file.edit(file)
64+
if (edit) fileEdit(file)
6565
}
6666

6767
addPackageJSON <- function(npmPkgs) {
@@ -89,7 +89,7 @@ addWidgetJS <- function(name, edit){
8989
'boilerplate for widget JavaScript bindings',
9090
list(name = name)
9191
)
92-
if (edit) utils::file.edit(file)
92+
if (edit) fileEdit(file)
9393
}
9494

9595
addExampleApp <- function(name) {

0 commit comments

Comments
 (0)