loops - Run external R script n times, with different input paramters, and save outputs in a data frame -


my question ties following problem:

run external r script n times , save outputs in data frame

the difference is, dont generate different results randomization functions use every time different set of input variables (e.g. run chunk of code range of latitudes lat=c(50,60,70,80))

has hint me? lot!

wrap script function putting:

my_function <- function(latitude) { 

at top and

} 

at bottom.

that way, source once then use ldply plyr package:

results <- ldply(10 * 5:8, myfunction) 

if wanted column identify latitude used, either add function's data.frame or use:

results <- ldply(10 * 5:8, function(lat) data.frame(latitude = lat, myfunction()) 

if reason didn't want modify script, create wrapper function:

my_wrapper <- function(a) {   latitude <-   source("script.r", local = true)$value } 

or use eval , parse:

my_function <- eval(parse(text = c("function(latitude) {",   readlines("script.r"), "}"))) 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -