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

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -