Learn R Programming

RWsearch (version 4.8.0)

cnsc: Conversion of Non-Standard Content into a Character Chain

Description

cnsc converts standard content and non-standard content ... into a character chain. Standard content, including calls, is evaluated. Non-standard content and non-existing objects (in .GlobalEnv) are converted into character chains. Regular lists are kept unchanged.

cnscinfun is intended to be used inside a function. It should not be used directly. If you find it appealing, copy the code of cnscinfun in your package and use it as an hidden function.

Usage

cnsc(...)

cnscinfun()

cnscinfun2(...)

Arguments

...

Character vectors, standard or non-standard, existing or non-existing R objects, regular call. Examples : "word1"; c("word1 word2"); c("word1", "word2"); "word1", "word2", "word3"; word1, word2, c("word3", "word4").

Examples

Run this code
# NOT RUN {
### cnsc
## Non-standard content (nsc1, nsc2), standard content ("stc3", "double word4") 
## and regular object (vec) stored in .GlobalEnv are merged.
vec <- c("obj5", "obj6")
cnsc(nsc1, nsc2, "stc3", "double word4", vec)

## Lists, either name in .GlobalEnv or call, are evaluated.
lst <- list(A = c("txt1","txt2","txt3"), B = c("txt4", "txt5"))
cnsc(lst) 
cnsc(list(C = c("pkg1","pkg2","pkg3"), D = c("pkg4","pkg5")))

### cnscinfun
fun <- function(...) cnscinfun()
fun(nsc1, nsc2, "stc3", "double word4", vec) 
fun(lst)

### cnscinfun used in RWsearch: one line at the begining of each function.
### An easy-to-use Non Standard Evaluation, mainly for characters.
funsort <- function(..., char = NULL) {
  words <- if (is.null(char)) cnscinfun() else char
  sort(words)
  # or more complex code 
}
funsort(nsc1, nsc2, "stc3", "double word4", vec) 
funsort(char = sample(vec, 5, replace = TRUE)) 

# }

Run the code above in your browser using DataLab