Reputation: 111
Is it possible to open (not run using source) a R script for editing from the console of R studio or R command line
Upvotes: 11
Views: 7704
Reputation: 2076
This is a nice command to edit an r script:
file.edit('foo.R')
Upvotes: 13
Reputation: 351
You could just read it like a text file and do anything you want with it. This can be done using the following syntax
SourceF <- file("Source.R", open = "r")
SourceF_lines <- readLines(SourceF)
To follow with someting like:
cat(SourceF_lines, sep = "\n")
## or
writeClipboard(SourceF_lines)
Or replace a specific part:
SourceF_lines[2] <- '## Do not run!!'
Upvotes: 2
Reputation: 132706
You can open a file for editing with edit
, e.g.,
edit(file = "test.R")
See help("edit")
for more information, in particular regarding different editors.
Upvotes: 7