Re: [R] looking for formula parser that allows coefficients

2018-08-24 Thread Gabor Grothendieck
The isChar function used in Parse is: isChar <- function(e, ch) identical(e, as.symbol(ch)) On Fri, Aug 24, 2018 at 10:06 PM Gabor Grothendieck wrote: > > Also here is a solution that uses formula processing rather than > string processing. > No packages are used. > > Parse <- function(e) { >

Re: [R] looking for formula parser that allows coefficients

2018-08-24 Thread Gabor Grothendieck
Also here is a solution that uses formula processing rather than string processing. No packages are used. Parse <- function(e) { if (length(e) == 1) { if (is.numeric(e)) return(e) else setNames(1, as.character(e)) } else { if (isChar(e[[1]], "*")) { x1 <- Recall(e[[2]])

Re: [R] looking for formula parser that allows coefficients

2018-08-22 Thread Gabor Grothendieck
Some string manipulation can convert the formula to a named vector such as the one shown at the end of your post. library(gsubfn) # input fo <- y ~ 2 - 1.1 * x1 + x3 - x1:x3 + 0.2 * x2:x2 pat <- "([+-])? *(\\d\\S*)? *\\*? *([[:alpha:]]\\S*)?" ch <- format(fo[[3]]) m <- matrix(strapplyc(ch, pat)[

Re: [R] looking for formula parser that allows coefficients

2018-08-21 Thread Fox, John
lsciences.mcmaster.ca/jfox/ > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul > Johnson > Sent: Tuesday, August 21, 2018 6:46 PM > To: R-help > Subject: [R] looking for formula parser that allows coefficients > > Can

[R] looking for formula parser that allows coefficients

2018-08-21 Thread Paul Johnson
Can you point me at any packages that allow users to write a formula with coefficients? I want to write a data simulator that has a matrix X with lots of columns, and then users can generate predictive models by entering a formula that uses some of the variables, allowing interactions, like y ~ 2