I'm attempting to pass a string argument into the function
randomForest but I get an error:
state <- paste(list("fruit ~",
"apples+oranges+blueberries",
"data=fruits.data, mtry=2, do.trace=100, na.action=na.omit,
keep.forest=TRUE"), sep= " ", collapse="")
model.rf <- randomForest(state)
Error in if (n==0) stop ("data(x) has 0 rows") argument is of length
zero.
-Thanks in advance,
mmv wrote:> I'm attempting to pass a string argument into the function > randomForest but I get an error: > > state <- paste(list("fruit ~", "apples+oranges+blueberries", > "data=fruits.data, mtry=2, do.trace=100, na.action=na.omit, > keep.forest=TRUE"), sep= " ", collapse="")I really don't understand why you want it as a character. I think you probably want to generate arguments dynamically and specify them in form of a list, which leads to constructions using do.call() at the end. Anyway, if you really want to call randomForest with the abouve text, I guess this is one of tzhe few circumstances where you can do eval(parse(.....)): state <- paste("fruit ~", "apples+oranges+blueberries,", "data=fruits.data, mtry=2, do.trace=100, na.action=na.omit, keep.forest=TRUE") the_call <- paste("randomForest(", state, ")") eval(parse(text=the_call)) Uwe Ligges> model.rf <- randomForest(state) > > Error in if (n==0) stop ("data(x) has 0 rows") argument is of length zero. > > -Thanks in advance, > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
If all you need the formula interface for is auto deletion of NAs, I'd
suggest doing something like:
varlist <- c("fruit", "apples", "oranges",
"blueberries")
fruits.nona <- na.omit(fruits.data[varlist])
model.rf <- randomForest(fruits.data[-1], fruits.data[[1]], ...)
If you want to know the call that produced model.rf, you can look at
model.rf$Call.
I hope that sort of answers your question.
Andy
> From: mmv
>
> I'm attempting to pass a string argument into the function
> randomForest but I get an error:
>
> state <- paste(list("fruit ~",
"apples+oranges+blueberries",
> "data=fruits.data, mtry=2, do.trace=100, na.action=na.omit,
> keep.forest=TRUE"), sep= " ", collapse="")
>
> model.rf <- randomForest(state)
>
> Error in if (n==0) stop ("data(x) has 0 rows") argument is of
> length zero.
>
> -Thanks in advance,
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
>