Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrote read functions in CPP #110

Merged
merged 3 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ notes.R
^\.travis\.yml$
^codecov\.yml$
^starwars\.ods$
^starwars\.fods$
^CRAN-RELEASE$
^doc$
^Meta$
^\.github$
^\.gitignore$
^codemeta\.json$
^benchmark$
^CRAN-SUBMISSION$
^tests/testdata/jts0501.ods$

^.vscode
^cran-comments\.md$

^.covrignore$
1 change: 1 addition & 0 deletions .covrignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/rapidxml
9 changes: 6 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Package: readODS
Type: Package
Title: Read and Write ODS Files
Version: 1.8.3
Authors@R: c(person("Gerrit-Jan", "Schutten", role = c("aut"), email = "[email protected]"), person("Chung-hong", "Chan", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0002-6232-7530")), person("Thomas J.", "Leeper", role = c("aut"), email = "[email protected]", comment = c(ORCID = "0000-0003-4097-6326")), person("John", "Foster", role = c("ctb"), email = "[email protected]"), person("Sergio", "Oller", role = c("ctb")), person("Jim", "Hester", role = c("ctb"), email = "[email protected]", comment = c(ORCID = "0000-0002-2739-7082")), person("Stephen", "Watts", role = c("ctb")), person("Arthur", "Katossky", role = c("ctb")), person("Stas", "Malavin", role = c("ctb")), person("Duncan", "Garmonsway", role = c("ctb")), person("Mehrad", "Mahmoudian", role = c("ctb")), person("Matt", "Kerlogue", role = c("ctb")), person("Detlef", "Steuer", role = c("aut"), email = "[email protected]", comment = c(ORCID = "0000-0003-2676-5290")), person("Michal", "Lauer", role = c("ctb"), email = "[email protected]"), person("Till", "Straube", role = c("ctb"), email = "[email protected]"))
Version: 1.9.0
Authors@R:
c(person("Gerrit-Jan", "Schutten", role = c("aut"), email = "[email protected]"), person("Chung-hong", "Chan", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0002-6232-7530")), person("Peter", "Brohan", role = c("aut"), email = "[email protected]"), person("Thomas J.", "Leeper", role = c("aut"), email = "[email protected]", comment = c(ORCID = "0000-0003-4097-6326")), person("John", "Foster", role = c("ctb"), email = "[email protected]"), person("Sergio", "Oller", role = c("ctb")), person("Jim", "Hester", role = c("ctb"), email = "[email protected]", comment = c(ORCID = "0000-0002-2739-7082")), person("Stephen", "Watts", role = c("ctb")), person("Arthur", "Katossky", role = c("ctb")), person("Stas", "Malavin", role = c("ctb")), person("Duncan", "Garmonsway", role = c("ctb")), person("Mehrad", "Mahmoudian", role = c("ctb")), person("Matt", "Kerlogue", role = c("ctb")), person("Detlef", "Steuer", role = c("aut"), email = "[email protected]", comment = c(ORCID = "0000-0003-2676-5290")), person("Michal", "Lauer", role = c("ctb"), email = "[email protected]"), person("Till", "Straube", role = c("ctb"), email = "[email protected]"))
Description: Read ODS (OpenDocument Spreadsheet) into R as data frame. Also support writing data frame into ODS file.
URL: https://github.com/ropensci/readODS
BugReports: https://github.com/ropensci/readODS/issues
Expand All @@ -14,7 +15,9 @@ Imports:
utils,
purrr,
zip
Suggests:
LinkingTo:
cpp11
Suggests:
dplyr,
testthat,
datasets,
Expand Down
7 changes: 4 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Generated by roxygen2: do not edit by hand

export(getNrOfSheetsInODS)
export(get_num_sheets_in_fods)
export(get_num_sheets_in_ods)
export(list_fods_sheets)
export(list_ods_sheets)
export(ods_sheets)
export(read.ods)
export(read_fods)
export(read_ods)
export(write_ods)
useDynLib(readODS, .registration = TRUE)
27 changes: 27 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# readODS 1.9.0

* Added a `NEWS.md` file to track changes to the package.
* Rewrote all reading functions in C++ for significant speed increase

## Removed read.ods and ods_sheets

These have been deprecated for several years.

## list_ods_sheets

* Added `include_external_data` as an argument (`FALSE` by default). This hides stored data from external sources not normally accessible to the user.

## read_ods

* Changed behaviour when only one row is read. The row now correctly appears as the top row in the dataframe, and a warning is given if column headers are requested that this would cause the output to be empty (**Note:** in this case column names are not assigned)
* Changed behaviour when only one column is read. Previously gave an error. If row names are requested, gives a warning that this would cause the output to be empty, and does not assign names.
* Sheets are now accepted as part of the `range` argument, e.g. `Range = "Sheet2!A2:B7"`. If this and the `sheets` argument are given, this is preferred.
* Merged cells now have their value places in the top-left cell. All other cells that would be covered by the merge are filled with `NA`.

## read_fods

* Reading (but not writing) flat ODS files is now supported using the functions `read_fods()`, `list_fods_sheets()`, `get_num_sheets_in_fods()`. These work the same way as their analogue ODS functions. The extension does not need to be `fods`, however they do need to conform to the OO specification.

## write_ods

* Attempted to fix writing non UTF-8 strings to files. This still has some issues in versions of R \< 4.2, however it should now correctly write most text within your current locale. See [readme](README.md) for more details.
17 changes: 17 additions & 0 deletions R/cpp11.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by cpp11: do not edit by hand

get_sheet_names_ <- function(file, include_external_data) {
.Call(`_readODS_get_sheet_names_`, file, include_external_data)
}

get_flat_sheet_names_ <- function(file, include_external_data) {
.Call(`_readODS_get_flat_sheet_names_`, file, include_external_data)
}

read_flat_ods_ <- function(file, start_row, stop_row, start_col, stop_col, sheet, formula_as_formula) {
.Call(`_readODS_read_flat_ods_`, file, start_row, stop_row, start_col, stop_col, sheet, formula_as_formula)
}

read_ods_ <- function(file, start_row, stop_row, start_col, stop_col, sheet, formula_as_formula) {
.Call(`_readODS_read_ods_`, file, start_row, stop_row, start_col, stop_col, sheet, formula_as_formula)
}
81 changes: 81 additions & 0 deletions R/list_ods_sheets.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#' List all sheets in an ODS File
#'
#' List all sheets in an ods file.
#'
#' @param path Path to the ods file
#' @param include_external_data A boolean value to show or hide sheets containing archived linked data (default false)
#' @return A character vector of sheet names.
#' @author Peter Brohan <peter.brohan+cran@@gmail.com>, Chung-hong Chan <chainsawtiney@@gmail.com>, Gerrit-Jan Schutten <phonixor@@gmail.com>
#' @examples
#' \dontrun{
#' # Get the list of names of sheets
#' list_ods_sheets("starwars.ods")
#' }
#' @seealso
#' use \code{\link{read_ods}} to read the data
#' @export
list_ods_sheets <- function(path, include_external_data = FALSE) {
return(get_sheet_names_(path, include_external_data))
}

#' Get the Number of Sheets in an ODS File
#'
#' Get the number of sheets in an ods file
#'
#' @param path path to the ods file
#' @param include_external_data A boolean value declaring if sheets holding archived linked data should be included
#' @return Number of sheets
#' @author Peter Brohan <peter.brohan+cran@@gmail.com>, Chung-hong Chan <chainsawtiney@@gmail.com>, Gerrit-Jan Schutten <phonixor@@gmail.com>
#' @examples
#' \dontrun{
#' # Get the number of sheets
#' get_num_sheets_in_ods("starwars.ods")
#' }
#' @seealso
#' use \code{\link{read_ods}} to read the data
#' @export
get_num_sheets_in_ods <- function(path, include_external_data = FALSE) {
sheets <- get_sheet_names_(path, include_external_data)
return(length(sheets))
}

#' List all sheets in an FODS File
#'
#' List all sheets in an fods file.
#'
#' @param path Path to the fods file
#' @param include_external_data A boolean value to show or hide sheets containing archived linked data (default false)
#' @return A character vector of sheet names.
#' @author Peter Brohan <peter.brohan+cran@@gmail.com>, Chung-hong Chan <chainsawtiney@@gmail.com>, Gerrit-Jan Schutten <phonixor@@gmail.com>
#' @examples
#' \dontrun{
#' # Get the list of names of sheets
#' list_fods_sheets("starwars.fods")
#' }
#' @seealso
#' use \code{\link{read_fods}} to read the data
#' @export
list_fods_sheets <- function(path, include_external_data = FALSE) {
return(get_flat_sheet_names_(path, include_external_data))
}

#' Get the Number of Sheets in an FODS File
#'
#' Get the number of sheets in an fods file
#'
#' @param path path to the fods file
#' @param include_external_data A boolean value declaring if sheets holding archived linked data should be included
#' @return Number of sheets
#' @author Peter Brohan <peter.brohan+cran@@gmail.com>, Chung-hong Chan <chainsawtiney@@gmail.com>, Gerrit-Jan Schutten <phonixor@@gmail.com>
#' @examples
#' \dontrun{
#' # Get the number of sheets
#' get_num_sheets_in_fods("starwars.fods")
#' }
#' @seealso
#' use \code{\link{read_fods}} to read the data
#' @export
get_num_sheets_in_fods <- function(path, include_external_data = FALSE) {
sheets <- get_flat_sheet_names_(path, include_external_data)
return(length(sheets))
}
3 changes: 3 additions & 0 deletions R/readODS-package.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#' @useDynLib readODS, .registration = TRUE
NULL

#' @keywords internal
"_PACKAGE"

Expand Down
Loading
Loading