check_and_convert: Check and Convert Data to Tibble

View source: R/check_and_convert.R

check_and_convertR Documentation

Check and Convert Data to Tibble

Description

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.

Usage

check_and_convert(data, verbose = TRUE)

Arguments

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.

Value

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.

Examples

## 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)

AndreSjuve/texaid documentation built on Oct. 20, 2024, 6:17 a.m.