Define (invisibly) caracas symbols in global environment

Define symbol for components in vector

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

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()
}
#>  [1] "i"  "j"  "n1" "n2" "n3" "x"  "x1" "x2" "x3" "y" 

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)
 }
#> c: [u₁  u₂  u₃]ᵀ