Re: [R] Read code from character string

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sat, 19 Jun 2010 05:19:35 -0400

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

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat 19 Jun 2010 - 09:22:49 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 20 Jun 2010 - 12:40:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive