[R] Read code from character string

Gabor Grothendieck ggrothendieck at gmail.com
Sat Jun 19 11:19:35 CEST 2010


On Sat, Jun 19, 2010 at 4:56 AM, Johannes Huesing <johannes at huesing.name> wrote:
> A rule would be a data structure containing the ID of the rule, the
> rule in human readable language, an expression evaluating variables
> within the environment of the appropriate data frame (and resolving to
> a logical vector), possibly the data frame itself, and the query
> message (possibly as an sprintf expression). The data structure may be
> an S4 object or a list. In our current workflow, we manage the
> validation rules using a spreadsheet, and import them into a
> competitor's analysis software.
>
> I could pass
>
> function(df) with(df, (vsstresn < 30 | vsstresn > 130) & vstestcd == "HR")

Another possibility would be to use an sql statement or fragment so if
you passed this sql fragment:

>   fragment <- "(vsstresn < 30 or vsstresn > 130) and vstestcd = 'HR'"
>
> # then your program would run this code:
>
>   df <- data.frame(vsstresn = seq(10, 200, 10), vstestcd = rep(c("HR", "RH"), c(16, 4)))
>   library(sqldf)
>   sqldf(paste("select * from df where", fragment))
  vsstresn vstestcd
1       10       HR
2       20       HR
3      140       HR
4      150       HR
5      160       HR



More information about the R-help mailing list