Create .R script to create another .R file into which arguments can be passed to
I'm aware of using R script to generate output to a new .R file.
However, I want to write actual code in the new R script that I can then pass arguments to and source later.
For example: In my original R code:
sink(file = "test code.R") bf_str = hist(rnorm(x)) sink()
(Here, the test file will not be generated because 'x' is not initialized)
My new .R file i.e., "test code.R" should ideally have
bf_str = hist(rnorm(x))
I should then be able to pass x = 100 and source the "test code.R" to generate the histogram like below:
x =100 input = source("test code.R")
Is there any way to do this? Any help is appreciated!