read_ods {readODS} | R Documentation |
Read Data From (F)ODS File
Description
read_ods is a function to read a single sheet from an (f)ods file and return a data frame. The function can be used for reading both ods and flat ods files.
(read_fods
) is also available, which can only read flat ods files.
Usage
read_ods(
path,
sheet = 1,
col_names = TRUE,
col_types = NULL,
na = "",
skip = 0,
formula_as_formula = FALSE,
range = NULL,
row_names = FALSE,
strings_as_factors = FALSE,
verbose = FALSE,
as_tibble = TRUE,
.name_repair = "unique",
ods_format = c("auto", "ods", "fods"),
guess = FALSE,
trim_ws = TRUE,
n_max = Inf
)
read_fods(
path,
sheet = 1,
col_names = TRUE,
col_types = NULL,
na = "",
skip = 0,
formula_as_formula = FALSE,
range = NULL,
row_names = FALSE,
strings_as_factors = FALSE,
verbose = FALSE,
as_tibble = TRUE,
.name_repair = "unique",
trim_ws = TRUE,
n_max = Inf
)
Arguments
path |
path to the (f)ods file. |
sheet |
sheet to read. Either a string (the sheet name), or an integer sheet number. The default is 1. |
col_names |
logical, indicating whether the file contains the names of the variables as its first line. Default is TRUE. |
col_types |
Either NULL to guess from the spreadsheet or refer to |
na |
Character vector of strings to use for missing values. By default read_ods converts blank cells to missing data. It can also be set to NULL, so that empty cells are treated as NA. |
skip |
the number of lines of the data file to skip before beginning to read data. If this parameter is larger than the total number of lines in the ods file, an empty data frame is returned. |
formula_as_formula |
logical, a switch to display formulas as formulas "SUM(A1:A3)" or as the resulting value "3"... or "8".. . Default is FALSE. |
range |
selection of rectangle using Excel-like cell range, such as |
row_names |
logical, indicating whether the file contains the names of the rows as its first column. Default is FALSE. |
strings_as_factors |
logical, if character columns to be converted to factors. Default is FALSE. |
verbose |
logical, if messages should be displayed. Default is FALSE. |
as_tibble |
logical, if the output should be a tibble (as opposed to a data.frame). Default is TRUE. |
.name_repair |
A string or function passed on as
Default is |
ods_format |
character, must be "auto", "ods" or "fods". The default "auto" is to determine the format automatically. By default, the format is determined by file extension, unless |
guess |
logical, If the file extension is absent or not recognized, this controls whether we attempt to guess format based on the file signature or "magic number". |
trim_ws |
logical, should leading and trailing whitespace be trimmed? |
n_max |
numeric, Maximum number of data rows to read. Ignored if |
Value
A tibble (tibble
) or data frame (data.frame
) containing a representation of data in the (f)ods file.
Author(s)
Peter Brohan peter.brohan+cran@gmail.com, Chung-hong Chan chainsawtiney@gmail.com, Gerrit-Jan Schutten phonixor@gmail.com
Examples
## Not run:
# Read an ODS file
read_ods("starwars.ods")
# Read a specific sheet, e.g. the 2nd sheet
read_ods("starwars.ods", sheet = 2)
# Read a specific range, e.g. A1:C11
read_ods("starwars.ods", sheet = 2, range = "A1:C11")
# Read an FODS file
read_ods("starwars.fods")
# Read a specific sheet, e.g. the 2nd sheet
read_ods("starwars.fods", sheet = 2)
# Read a specific range, e.g. A1:C11
read_ods("starwars.fods", sheet = 2, range = "A1:C11")
# Give a warning and read from Sheet1 (not 2)
read_ods("starwars.fods", sheet = 2, range = "Sheet1!A1:C11")
# Specifying col_types as shorthand, the third column as factor; other by guessing
read_ods("starwars.ods", col_types = "??f")
# Specifying col_types as list
read_ods("starwars.ods", col_types = list(species = "f"))
# Using read_fods, although you don't have to
read_ods("starwars.fods")
## End(Not run)