read_ods is a function to read a single sheet from an (f)ods file and return a data frame. For flat ods files (.fods or .xml),
use (read_fods
).
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"
)
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"
)
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
readr::type_convert()
to specify cols specification. It can also be a shorthand such as "ccf" ("character", "character", "factor"), a list, or an object created byreadr::cols()
. NA will return a data frame with all columns being "characters". Please note that it will not speed up the reading by a lot by specifying this parameter explicitly. It is more for accuracy.- 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
range = "D12:F15"
orrange = "R1C12:R6C15"
. Cell range processing is handled by thecellranger
package. If sheet name is in the range, such asrange = "Sheet2!A2:B7"
, this sheet name is used instead of the providedsheet
. Ifsheet
is not the default value (1), a warning is given.- 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
.name_repair
totibble::as_tibble()
"minimal"
: No name repair"unique"
: Make sure names are unique and not empty"check_unique"
: Check names are unique, but do not repair"universal"
: Checks names are unique and valid R variables names in scopeA function to apply custom name repair.
Default is
"unique"
.
Value
A tibble (tibble
) or data frame (data.frame
) containing a representation of data in the (f)ods file.
Author
Peter Brohan [email protected], Chung-hong Chan [email protected], Gerrit-Jan Schutten [email protected]
Examples
if (FALSE) {
# 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_fods("starwars.fods")
# Read a specific sheet, e.g. the 2nd sheet
read_fods("starwars.fods", sheet = 2)
# Read a specific range, e.g. A1:C11
read_fods("starwars.fods", sheet = 2, range = "A1:C11")
# Give a warning and read from Sheet1 (not 2)
read_fods("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"))
}