line_to_vector | R Documentation |
This function takes a line of items separated by spaces, tabs, or newlines and
returns either a c()
vector command (with items quoted or not) or the vector
created by that command. By default, the line is read from the clipboard and
a character vector is returned. The function uses only the highest-level
separator present in x
unless specified otherwise. This functionality is
particularly useful for copying values from spreadsheet programs like Excel
(or from R console output) and converting them into R vectors seamlessly.
line_to_vector(
x = NULL,
strings = NULL,
separators = c("top-level", "all"),
to_clip = interactive(),
return = c("code", "vector"),
keep_blank_as_na = FALSE
)
l2v(
x = NULL,
strings = NULL,
separators = c("top-level", "all"),
to_clip = interactive(),
return = c("code", "vector"),
keep_blank_as_na = FALSE
)
x |
Character string of desired vector items, separated by spaces, tabs,
or line breaks. If |
strings |
Logical or |
separators |
Character string indicating which separator should be used
to split |
to_clip |
Logical. Indicates whether the generated code for the vector
should be copied to the clipboard. Defaults to |
keep_blank_as_na |
Logical. If |
return_type |
Character string specifying the type of return value.
Choose |
If x
is not split by spaces, stringr::str_trim()
is used to trim
whitespace from the start and end of each element of the vector.
A character string representing the c()
command or the actual R
vector, depending on the return_type
parameter.
line_to_vector("a b c", strings = TRUE)
# c("a", "b", "c")
line_to_vector("1 2 3", return_type = "vector")
# [1] 1 2 3
# Can abbreviate return argument
# [1] "Friday" "Saturday" "Sunday"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.