View source: R/check_and_convert.R
check_and_convert | R Documentation |
This function checks whether the input data is a data frame or a tibble.
If the input is neither, it attempts to convert it to a tibble.
It provides informative messages based on the verbose
argument.
check_and_convert(data, verbose = TRUE)
data |
The data to be checked and potentially converted. It can be a data frame, tibble, or other data structures that can be converted to a tibble. |
verbose |
A logical value indicating whether to print informational messages during the process. Defaults to TRUE. |
Returns the input data as a tibble if it was successfully converted, or the original data if it was already a data frame or tibble.
## Not run:
# Example with a data frame
df <- data.frame(a = 1:3, b = 4:6)
check_and_convert(df) # Should return the original data frame as a tibble
# Example with a tibble
tb <- tibble::tibble(a = 1:3, b = 4:6)
check_and_convert(tb) # Should return the original tibble
# Example with a numeric vector (should convert to tibble)
vec <- c(1, 2, 3)
check_and_convert(vec) # Should return a tibble with a single column
# Example with an incompatible structure
invalid_data <- list(a = 1, b = 2)
check_and_convert(invalid_data) # Should raise an error
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.