Description Usage Arguments Value Author(s) Examples
Hard coding isn't the best practice, but sometimes it's useful, especially in one-off scripts for analyses. An typical example would be to select a large number of columns in a dataset by their names. This function facilitate hard coding constants into R by printing the code from a vector that would be needed to create that vector.
1 |
x |
A vector (numeric, character, logical, or complex) |
vname |
A string indicating the name of the vector that will be "created" in the code |
vert |
A logical indicating whether the vector should be coded vertically ( |
... |
Additional arguments to |
Prints code (via cat
) that will create the vector. This code
can then be copied into other source code. Returns nothing.
Landon Sego
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # With characters
hardCode(letters[1])
hardCode(letters[1:3], vname = "new")
hardCode(letters[1], vert = FALSE)
hardCode(letters[1:3], vert = FALSE, vname = "new")
# With numbers
hardCode(3:5)
hardCode(3:5, vert = FALSE, vname = "num")
# With logicals
hardCode(TRUE)
hardCode(c(FALSE, TRUE), vert = FALSE)
hardCode(c(TRUE, FALSE, TRUE), vname = "newLogical")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.