Reval: R Utilities: Evaluates a String as an Expression in R

Description Usage Arguments Details Examples

View source: R/Reval.R

Description

This function evaluates a string as an R expression.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
Reval(Rstring, print.string=TRUE, n.eval.parent=1)

# Reval( print(Rstring) )
Revalpr(Rstring, print.string=TRUE)

#  Reval( print(str(Rstring)) )
Revalprstr(Rstring, print.string=TRUE)

#  Reval( print(round(Rstring, digits)) )
Revalpr_round( Rstring, digits=5, print.string=TRUE)

#  Reval( print(max(abs(Rstring_x - Rstring_y)) ) )
Revalpr_maxabs( Rstring_x, Rstring_y, print.string=TRUE, na.rm=FALSE)

Arguments

Rstring

String which shall be evaluated in R

print.string

Should the string printed on the console?

n.eval.parent

Index of parent environment in which the R command should be evaluated.

digits

Number of digits after decimal.

Rstring_x

String corresponding to an R object

Rstring_y

String corresponding to an R object

na.rm

Logical indicating whether missing values should be removed from calculation

Details

The string is evaluated in the parent environment. See base::eval for the definition of environments in R.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# This function is simply a shortage function
# See the definition of this function:
Reval <- function( Rstring, print.string=TRUE){
    if (print.string){ cat( paste( Rstring ), "\n"  ) }
        eval.parent( parse( text=paste( Rstring )), n=1 )
            }

Reval( "a <- 2^3" )
  ## a <- 2^3
a
  ## [1] 8

alexanderrobitzsch/miceadds documentation built on Dec. 12, 2018, 2:41 a.m.