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

View source: R/Reval.R

RevalR Documentation

R Utilities: Evaluates a String as an Expression in R

Description

This function evaluates a string as an R expression.

Usage

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

# 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

miceadds documentation built on May 29, 2024, 11:05 a.m.