Run multiple R Scripts in R Studio

后端 未结 1 907
感动是毒
感动是毒 2021-02-04 19:50

I am having a lot of R Scripts created by RStudio, and I am wondering if there is a method to run all of them in RStudio with a single step instead of open and run each of them

相关标签:
1条回答
  • 2021-02-04 19:55

    You could have one main script that sources the others and just run the main script.

    main.R

    print("Hello main")
    source("blah.R")
    source("foo.R")
    

    blah.R

    print("Hello blah")
    

    foo.R

    print("Hello foo")
    

    Run them all by sourcing main.R

    > source("main.R")
    [1] "Hello main"
    [1] "Hello blah"
    [1] "Hello foo"
    > ?source
    

    source {base}

    source causes R to accept its input from the named file or URL or connection. Input is read and parsed from that file until the end of the file is reached, then the parsed expressions are evaluated sequentially in the chosen environment.

    0 讨论(0)
提交回复
热议问题