I am working with Rstudio and have written a script which at some point does
file.edit('blah')
When I run this line a new tab in the IDE opens up titled 'blah' and I am free to edit and save the file. If the file 'blah' existed this then file is the one opened. Otherwise it is temporarily created.
I wanted to include the line in a package I was writing so I did
utils::file.edit('blah')
This does not produce the same effect however. Instead an Rstudio pop-up Window. If the file 'blah' existed this file is the one opened, otherwise it is temporarily created.
I would like to know, if it is at all possible to configuring utils::file.edit to open in the same way that file.edit does.
For further information if I type:
file.edit
I get
function (...)
.rs.callAs(name, hook, original, ...)
Whereas, if I type
utils::file.edit
I get
function (..., title = file, editor = getOption("editor"),
fileEncoding = "")
{
file <- path.expand(c(...))
title <- rep_len(as.character(title), length(file))
if (nzchar(fileEncoding) && fileEncoding != "native.enc") {
tfile <- file
for (i in seq_along(file)) {
tfile <- tempfile()
con <- file(file[i], encoding = fileEncoding)
writeLines(readLines(con), tfile)
close(con)
file[i] <- tfile
}
}
if (is.function(editor))
invisible(editor(file = file, title = title))
else invisible(.External2(C_fileedit, file, title, editor))
}
<bytecode: 0x000001786f4a17b8>
<environment: namespace:utils>
If I do:
utils_env<-as.environment('package:utils')
utils_env$file.edit
I see
function (...)
.rs.callAs(name, hook, original, ...)
<environment: 0x000001bedbc1b8d0>
Which is further confusing, as I would have expected the version of file.edit from the package to match the one in the package environment.
So my surface level question is how can I write my package so that Rstudio opens the file for editing the way I want. But the deeper question is What is going on here? Does Rstudio overwrite the file.edit function at start-up, and then how can I call my preferred version of file.edit?
Thanks for taking the time to read, really grateful if you can help.