Difference between revisions of "Parser.R"

From Organic Design wiki
(Adding parser examples)
 
(Note)
Line 3: Line 3:
 
# Std output & Std error
 
# Std output & Std error
 
# The parser tries to evaluate the expression in the console (unless character)
 
# The parser tries to evaluate the expression in the console (unless character)
 +
# See also p 34 part-02.pdf (Ihakas 2006 workshop)
 
# ----------------------------------------------------------------------------- #
 
# ----------------------------------------------------------------------------- #
  

Revision as of 00:31, 1 December 2006

  1. -------------------- Examples demonstrating the R parser -------------------- #
  2. Std input
  3. Std output & Std error
  4. The parser tries to evaluate the expression in the console (unless character)
# See also p 34 part-02.pdf (Ihakas 2006 workshop)
  1. ----------------------------------------------------------------------------- #
  1. expression() Creates or tests for objects of mode
  2. eval() Evaluate an R expression in a specified environment
  3. quote() Simply returns its argument. The argument is not evaluated and can be any R expression.
  4. evalq 'evalq' form is equivalent to 'eval(quote(expr), ...)'.
  5. substitute() Substituting and Quoting Expressions
  6. parse() Returns the parsed but unevaluated expressions in a list. Each element of the list is of mode 'expression'.
  7. deparse() Turn unevaluated expressions into character strings

x <- expression(1 + 0:9) x length(x) mode(x) eval(x)

x <-expression({a <- 1:10; a^2}) eval(x)

quote(x<1 & y>=10) quote(x) evalq(x) eval(quote(x)) # identical

  1. substitute allows env auxillary information

substitute(expression(a + b), list(a = 1))

example(parse) parse(text="x < b & y >= 3") x <- "x < b & y >= 3" parse(text=x)


eval(expression("x < b & y >= 3")) eval(expression(x))

  1. identical (fails if x, b, and y cannot be found)

eval(parse(text="x < b & y >= 3")) eval(parse(text=x))