Writing a code to create an empty source R file and then run the script from that source file in my current R file


I would like to write a code in an existing R file that I am working in so that my code when executed creates a new blank source R file and saves this source file to a specific directory.

Then I would proceed to write the following commands in my newly created source R file

  1. flag <- runif(100)
  2. print(flag)

I would not execute these commands in my source R file rather just write the code .
Finally, I need to write a code in my current R file that would read all these commands from the source R file and execute in my current R file to produce the results.

Thanks in advance for your help!!

Can you motivate the desire for this seemingly purposeless level of indirection?

1 Like

This was for a college project as part of an introductory course in programming. Anyhow I was able to figure it out.