Learn R Programming

macro (version 0.1.5)

symget: Get a Variable Value from the Macro Symbol Table

Description

The symget function extracts the value of a single macro variable from the macro symbol table.

Usage

symget(name)

Value

The value of the macro variable as a character string. If the variable name is not found, the function will return an NA.

Arguments

name

The name of the macro variable as a quoted string, with no leading ampersand or trailing dot ("."). The leading ampersand will be added automatically by the function. This parameter is required.

See Also

msource()

Other symtable: print.symtable(), symclear(), symput(), symtable()

Examples

Run this code
library(macro)

# Get path to demo macro program
src <- system.file("extdata/Demo3.R", package = "macro")

# Display source code
# - This is the macro input code
cd <- readLines(src)
cat(paste(cd, "\n"))
# #% Determine appropriate data path
# #%if ("&env." == "prod")
#   #%let pth <- /projects/prod/data
# #%else
#   #%let pth <- /projects/dev/data
# #%end

# Set environment variable using symput()
symput("env", "prod")

# Macro Execute Source Code
# - set clear to FALSE to so "env" value is not removed
msource(src, echo = FALSE, clear = FALSE)

# View "pth" macro variable
res <- symget("pth")

# View results
# - Path is set to the "prod" value
res
# [1] "/projects/prod/data"

Run the code above in your browser using DataLab