| file_schema_dsv | R Documentation |
The file_schema_dsv() function returns a data frame with the schema
of a DSV file reading only the first max_lines of a delimiter
separated values (DSV) text file to infer column names and data types
(it does not read the full dataset into memory). Then it converts them
to the candidate data frame columns' names and data types.
file_schema_dsv(
input_file,
header = TRUE,
sep = ",",
dec = ".",
grp = "",
id_quote_method = "DB_NAMES",
max_lines = 2000,
null_columns = FALSE,
force_num_cols = TRUE,
...
)
input_file |
character, file name (including path) to be read. |
header |
logical, if |
sep |
character, field delimiter (e.g., "," for CSV, "\t" for TSV) in the input file. Defaults to ",". |
dec |
character, decimal separator (e.g., "." or "," depending on locale) in the input file. Defaults to ".". |
grp |
character, character used for digit grouping. It defaults
to |
id_quote_method |
character, used to specify how to build the SQLite
columns' names using the fields' identifiers read from the input file.
For details see the description of the |
max_lines |
integer, number of lines (excluding the header) to be read to infer columns' data types. Defaults to 2000. |
null_columns |
logical, if |
force_num_cols |
logical, if |
... |
Additional arguments for quoting and data interpretation as
described in the
|
a list with the following named elements:
schema, a data frame with these columns:
col_names: columns' names, after applying the selected quote method;
col_names_unquoted: columns' names, unquoted; if id_quote_method
is set to DB_NAMES they will be the same as col_names; for other
quote methods they will be the unquoted versions of col_names,that
is generally the same as src_names unless src_names contain the
quoting characters;
col_types: columns' R data types;
sql_types: columns' SQLite data types;
src_names: columns' names as they appear in the input file.
src_types: defaults to text for all columns.
src_is_quoted: logical vector indicating if each column has at least
one value enclosed in quotes.
all_na: logical vector indicating if each column consists only of NAs.
col_counts, a data frame with these columns:
num_col: number of columns,
Freq: number of rows (within max_lines) that have the number
of colums shown in num_col.
n_cols, integer, the number of columns selected for the file.
num_col, a vector of integers of length max_lines with the
number of detected columns in each row tested.
col_fill, logical, it is set to TRUE if there are lines with
less columns than n_cols.
col_flush, logical, it is set to TRUE if there are lines with
more columns than n_cols.
# Inspect CSV file schema without loading full dataset
data_path <- system.file("extdata", package = "RSQLite.toolkit")
# Get schema information for abalone CSV
schema_info <- file_schema_dsv(
input_file = file.path(data_path, "abalone.csv"),
header = TRUE,
sep = ",",
dec = ".",
max_lines = 50
)
# Display schema information
print(schema_info$schema[, c("col_names", "col_types", "sql_types")])
# Check column consistency
print(schema_info$col_counts)
print(paste("Guessed columns:", schema_info$n_cols))
# Example with different parameters
schema_custom <- file_schema_dsv(
input_file = file.path(data_path, "abalone.csv"),
header = TRUE,
sep = ",",
dec = ".",
max_lines = 50,
id_quote_method = "SQL_SERVER"
)
print(schema_custom$schema[, c("col_names", "col_types", "src_names")])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.