0

I have an already saved R script, say "analysis1.R". I use source("analysis1.R") command to run the R script when required in a different code.

How does one execute only the required lines of code? Say first 10 lines of the code ("analysis1.R")?

Heikki
  • 2,214
  • 19
  • 34
  • 1
    Possible duplicate of [Automate script execution](https://stackoverflow.com/questions/55518732/automate-script-execution) – NelsonGon Apr 21 '19 at 12:34
  • Here is a partial solution I found. Say from=1 and to=10 x = scan("analysis1.R", what = character(), sep = '\n', skip = from - 1, n = to - from + 1, encoding = 'UTF-8', quiet = TRUE) eval.parent(parse(text=x)) – Sesha Meka Apr 21 '19 at 15:26
  • For the detailed post see: https://stackoverflow.com/questions/12214963/source-only-part-of-a-file – Sesha Meka Apr 21 '19 at 15:30

1 Answers1

0
from=1 
to=10
x = scan("analysis1.R", what = character(),
    sep = '\n', skip = from - 1, n = to - from + 1,
    encoding = 'UTF-8', quiet = TRUE) 
eval.parent(parse(text=x))
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92