printc: Print vector literal code for a string Vector

View source: R/misc.R View source: R/RMD_utils.R

printcR Documentation

Print vector literal code for a string Vector

Description

Sometimes we need to write a vector which values come from data, which means to manually copy values and write into a vector definition. This function will take a vector (often came from data, like all unique values of a category column) and print a vector definition string, then it can be copied to source code.

It's often needed to create a vector literally even the vector can be obtained in code. For example a sbuset of column names can be get with number index, but it's not safe to use number index in code. Use this function to turn the output of number index into literal format, then you can copy the output to code.

Usage

printc(x)

printc(x)

Arguments

x

a vector holding items x1, x2, ...

Value

string of "c("x1", "x2")"

Examples

printc(letters[1:3])
printc(names(mtcars)[1:3])


dracodoc/mischelper documentation built on Jan. 17, 2025, 11:03 a.m.