def_sym: Define (invisibly) caracas symbols in global environment

View source: R/sym_def_sym.R

def_symR Documentation

Define (invisibly) caracas symbols in global environment

Description

Define (invisibly) caracas symbols in global environment

Define symbol for components in vector

Usage

def_sym(..., charvec = NULL, warn = FALSE, env = parent.frame())

def_sym_vec(x, env = parent.frame())

Arguments

...

Names for new symbols, also supports non-standard evaluation

charvec

Take each element in this character vector and define as caracas symbols

warn

Warn if existing variable names are overwritten

env

The environment in which the assignment is made.

x

Character vector.

Value

Names of declared variables (invisibly)

See Also

symbol(), as_sym()

Examples

if (has_sympy()) {
  ls()
  def_sym(n1, n2, n3)
  ls()
  def_sym("x1", "x2", "x3")
  ls()
  # def_sym("x1", "x2", "x3", warn = TRUE) # Do not run as will cause a warning
  ls()
  def_sym(i, j, charvec = c("x", "y"))
  ls()
}

if (has_sympy()) {
  def_sym(z1, z2, z3)
  u <- paste0("u", seq_len(3))
  ## Creates symbols u1, u2, u3 and binds to names u1, u2, u3 in R.
  def_sym_vec(u) 
  ## Same as (but easier than)
  def_sym(u1, u2, u3)
  ## Notice: this creates matrix [u1, u2, u3]
  as_sym(u)
 }

caracas documentation built on June 22, 2024, 10:59 a.m.