How to manage very long R functions in VBA

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to manage very long R functions in VBA

Cren
Hi all,

I'm having the following issue: let I'm using RExcel's command

RInterface.RRun "y <- function(x) {...}"

If y is a short function, there's no issue; but usually the y function I write is very long: in RStudio, as instance, it may take 20 ~ 30 rows.

In VBA I can use " ; " to separate each command of functions, but this forces me to write very very long command lines because I have to put one functions' row next to the following, creating kilometric sequences of commands.

Consider this R function:

y <- function(x) {
     a <- x^2
     b <- a * 3
     c <- b / 2
     return(c)
}


In VBA I'm used to write:

RInterface.RRun "y <- function(x) {a <- x^2 ;  b <- a * 3 ; c <- b / 2 ; return(c)}"

How may I wrap?

Thanks,

Reply | Threaded
Open this post in threaded view
|

Re: How to manage very long R functions in VBA

Bart Joosen
Not tested, but how about:

RInterface.RRun "y <- function(x) { " _
& "    a <- x^2 ;" _
&"     b <- a * 3 ;" _
& "     c <- b / 2 ;" _
& "     return(c) }"

Good luck

Bart