Title: | Read and Write ODS Files |
---|---|
Description: | Read ODS (OpenDocument Spreadsheet) into R as data frame. Also support writing data frame into ODS file. |
Authors: | Gerrit-Jan Schutten [aut], Chung-hong Chan [aut, cre] , Peter Brohan [aut], Detlef Steuer [aut] , Thomas J. Leeper [aut] , John Foster [ctb], Sergio Oller [ctb], Jim Hester [ctb] , Stephen Watts [ctb], Arthur Katossky [ctb], Stas Malavin [ctb], Duncan Garmonsway [ctb], Mehrad Mahmoudian [ctb], Matt Kerlogue [ctb], Michal Lauer [ctb], Till Straube [ctb], Marcin Kalicinski [ctb, cph] (Author of included RapidXML code) |
Maintainer: | Chung-hong Chan <[email protected]> |
License: | GPL-3 |
Version: | 2.3.1 |
Built: | 2024-11-12 11:14:59 UTC |
Source: | https://github.com/ropensci/readODS |
list_ods_sheets
lists all sheets in an (f)ods file. The function can be used for listing sheets in both ods and flat ods files. (list_fods_sheets
) is also available, which can only list sheets in flat ods files.
list_ods_sheets( path, include_external_data = FALSE, ods_format = c("auto", "ods", "fods"), guess = FALSE ) list_fods_sheets(path, include_external_data = FALSE) ods_sheets(path)
list_ods_sheets( path, include_external_data = FALSE, ods_format = c("auto", "ods", "fods"), guess = FALSE ) list_fods_sheets(path, include_external_data = FALSE) ods_sheets(path)
path |
Path to the (f)ods file |
include_external_data |
A boolean value to show or hide sheets containing archived linked data (default false) |
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". |
The default "include_external_data" for ods_sheets
is TRUE to maintain compatibility with version 1 of readODS. It will change to TRUE
in version 3.
A character vector of sheet names
Peter Brohan [email protected], Chung-hong Chan [email protected], Gerrit-Jan Schutten [email protected]
use read_ods
to read the data
## Not run: # Get the list of names of sheets list_ods_sheets("starwars.ods") list_ods_sheets("starwars.fods") # Using list_fods_sheets, although you don't have to list_fods_sheets("starwars.fods") ## End(Not run)
## Not run: # Get the list of names of sheets list_ods_sheets("starwars.ods") list_ods_sheets("starwars.fods") # Using list_fods_sheets, although you don't have to list_fods_sheets("starwars.fods") ## End(Not run)
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.
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 )
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 )
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 |
A tibble (tibble
) or data frame (data.frame
) containing a representation of data in the (f)ods file.
Peter Brohan [email protected], Chung-hong Chan [email protected], Gerrit-Jan Schutten [email protected]
## 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)
## 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)
Function to write a single data frame or a list of data frames to a (f)ods file.
write_ods( x, path = tempfile(fileext = ".ods"), sheet = "Sheet1", append = FALSE, update = FALSE, row_names = FALSE, col_names = TRUE, na_as_string = FALSE, padding = FALSE ) write_fods( x, path = tempfile(fileext = ".fods"), sheet = "Sheet1", append = FALSE, update = FALSE, row_names = FALSE, col_names = TRUE, na_as_string = FALSE, padding = FALSE )
write_ods( x, path = tempfile(fileext = ".ods"), sheet = "Sheet1", append = FALSE, update = FALSE, row_names = FALSE, col_names = TRUE, na_as_string = FALSE, padding = FALSE ) write_fods( x, path = tempfile(fileext = ".fods"), sheet = "Sheet1", append = FALSE, update = FALSE, row_names = FALSE, col_names = TRUE, na_as_string = FALSE, padding = FALSE )
x |
data frame or list of data frames that will be sheets in the (f)ods. If the list is named, the names are used as sheet names |
path |
Path to the (f)ods file to write |
sheet |
Name of the sheet; ignore if |
append |
logical, TRUE indicates that x should be appended to the existing file (path) as a new sheet. If a sheet with the same sheet_name exists, an exception is thrown. See update. Please also note that writing is slightly slower if TRUE. Default is FALSE. Ignore if |
update |
logical, TRUE indicates that the sheet with sheet_name in the existing file (path) should be updated with the content of x. If a sheet with sheet_name does not exist, an exception is thrown. Please also note that writing is slightly slower if TRUE. Default is FALSE. Ignore if |
row_names |
logical, TRUE indicates that row names of x are to be included in the sheet. Default is FALSE |
col_names |
logical, TRUE indicates that column names of x are to be included in the sheet. Default is TRUE |
na_as_string |
logical, TRUE indicates that NAs are written as string; FALSE indicates that NAs are written as empty cells |
padding |
logical, TRUE indicates that the sheet is padded with repeated empty cells to the maximum size, either 2^20 x 1024 (if the number of columns of |
This function emulates writexl::write_xlsx()
except in the handling of list columns. The expected behaviour for this is undefined and the two functions behave differently. This function handles list columns by converting them to character vectors of R code (similar to the output of dput()
), which is probably not ideal.
A (F)ODS file written to the file path location specified by the user. The value of path
is also returned invisibly
Detlef Steuer [email protected], Thomas J. Leeper [email protected], John Foster [email protected], Chung-hong Chan [email protected]
## Not run: # preserve the row names write_ods(mtcars, "mtcars.ods", row_names = TRUE) # append a sheet to an existing file write_ods(PlantGrowth, "mtcars.ods", append = TRUE, sheet = "plant") # This is however faster write_ods(list("Sheet1" = mtcars, "plant" = PlantGrowth), "mtcars.ods", row_names = TRUE) # write flat ODS file write_fods(mtcars, "mtcars.fods", sheet = "mtcars") ## End(Not run)
## Not run: # preserve the row names write_ods(mtcars, "mtcars.ods", row_names = TRUE) # append a sheet to an existing file write_ods(PlantGrowth, "mtcars.ods", append = TRUE, sheet = "plant") # This is however faster write_ods(list("Sheet1" = mtcars, "plant" = PlantGrowth), "mtcars.ods", row_names = TRUE) # write flat ODS file write_fods(mtcars, "mtcars.fods", sheet = "mtcars") ## End(Not run)