Include and run different scripts in one RStudio script

Hi

I am looking for an example on how to include and run different scripts in one RStudio script.

For example I have two separate scripts: Tes1.R and Test2.R
The idea is then to have a master RStudio file where I include and run the previous scripts in a sequence:
Test1.R
Test2.R

I have seen that a similar question was raised in past discussion but not specifically referring to RStudio. A simple exemple to start with would be really helpful to me.

You can use R's source() command to do this. Create a main.R file and inside it, run the other two scripts:

source("Test1.R")
source("Test2.R")

Docs: source function - RDocumentation

Thank you. This is what i already tried to but encountered errors. However If i run the script directly I have no issues. Please see below:

source("M:\\Org\\BLW_3210_INTERN\\R\\Prices_P2\\WORLD_prices_1_toa.R")

Returned this error:

source("M:\Org\BLW_3210_INTERN\R\Prices_P2\WORLD_prices_1_toa.R")
Error in source("M:\Org\BLW_3210_INTERN\R\Prices_P2\WORLD_prices_1_toa.R") :
M:\Org\BLW_3210_INTERN\R\Prices_P2\WORLD_prices_1_toa.R:9:12: unexpected input
8: skip = 19) %>%
9: select(Wä
^

these glyphs stand out to me that its likely a source encoding issue,
perhaps browse this thread and consider some of the suggestions
How to source() .R file saved using UTF-8 encoding? - Stack Overflow

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.