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

Change .name_repair for name_repair for consistency #762

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ Depends:
R (>= 3.6)
Imports:
cellranger,
lifecycle,
tibble (>= 2.0.1),
utils
Suggests:
covr,
knitr,
rmarkdown,
testthat (>= 3.1.6),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ importFrom(cellranger,anchored)
importFrom(cellranger,cell_cols)
importFrom(cellranger,cell_limits)
importFrom(cellranger,cell_rows)
importFrom(lifecycle,deprecated)
useDynLib(readxl, .registration = TRUE)
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# readxl (development version)

* `.name_repair` is now deprecated in favour of `name_repair` (@olivroy, #729).

# readxl 1.4.3

This release contains no user-facing changes.
Expand Down
64 changes: 46 additions & 18 deletions R/read_excel.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@
#' only in an interactive session, outside the context of knitting a document,
#' and when the call is likely to run for several seconds or more. See
#' [readxl_progress()] for more details.
#' @param .name_repair Handling of column names. Passed along to
#' [tibble::as_tibble()]. readxl's default is `.name_repair = "unique", which
#' @param name_repair Handling of column names. Passed along to
#' [tibble::as_tibble()]. readxl's default is `name_repair = "unique"`, which
#' ensures column names are not empty and are unique.
#' @param .name_repair `r lifecycle::badge("deprecated")`. Use `name_repair` instead.
#' @return A [tibble][tibble::tibble-package]
#' @seealso [cell-specification] for more details on targetting cells with the
#' `range` argument
Expand Down Expand Up @@ -92,46 +93,55 @@
#' # Get a preview of column names
#' names(read_excel(readxl_example("datasets.xlsx"), n_max = 0))
#'
#' # exploit full .name_repair flexibility from tibble
#' # exploit full name_repair flexibility from tibble
#'
#' # "universal" names are unique and syntactic
#' read_excel(
#' readxl_example("deaths.xlsx"),
#' range = "arts!A5:F15",
#' .name_repair = "universal"
#' name_repair = "universal"
#' )
#'
#' # specify name repair as a built-in function
#' read_excel(readxl_example("clippy.xlsx"), .name_repair = toupper)
#' read_excel(readxl_example("clippy.xlsx"), name_repair = toupper)
#'
#' # specify name repair as a custom function
#' my_custom_name_repair <- function(nms) tolower(gsub("[.]", "_", nms))
#' read_excel(
#' readxl_example("datasets.xlsx"),
#' .name_repair = my_custom_name_repair
#' name_repair = my_custom_name_repair
#' )
#'
#' # specify name repair as an anonymous function
#' read_excel(
#' readxl_example("datasets.xlsx"),
#' sheet = "chickwts",
#' .name_repair = ~ substr(.x, start = 1, stop = 3)
#' name_repair = ~ substr(.x, start = 1, stop = 3)
#' )
read_excel <- function(path, sheet = NULL, range = NULL,
col_names = TRUE, col_types = NULL,
na = "", trim_ws = TRUE, skip = 0, n_max = Inf,
guess_max = min(1000, n_max),
progress = readxl_progress(),
.name_repair = "unique") {
name_repair = "unique",
.name_repair = deprecated()) {
path <- check_file(path)
format <- check_format(path)
if (lifecycle::is_present(.name_repair)) {
lifecycle::deprecate_warn(
"1.5.0",
"read_excel(.name_repair)",
"read_excel(name_repair)"
)
name_repair <- .name_repair
}
read_excel_(
path = path, sheet = sheet, range = range,
col_names = col_names, col_types = col_types,
na = na, trim_ws = trim_ws, skip = skip,
n_max = n_max, guess_max = guess_max,
progress = progress,
.name_repair = .name_repair,
name_repair = name_repair,
format = format
)
}
Expand All @@ -147,15 +157,24 @@
na = "", trim_ws = TRUE, skip = 0, n_max = Inf,
guess_max = min(1000, n_max),
progress = readxl_progress(),
.name_repair = "unique") {
name_repair = "unique",
.name_repair = deprecated()) {
path <- check_file(path)
if (lifecycle::is_present(.name_repair)) {
lifecycle::deprecate_warn(
"1.5.0",
"read_xls(.name_repair)",
"read_xls(name_repair)"
)
name_repair <- .name_repair

Check warning on line 169 in R/read_excel.R

View check run for this annotation

Codecov / codecov/patch

R/read_excel.R#L164-L169

Added lines #L164 - L169 were not covered by tests
}
read_excel_(
path = path, sheet = sheet, range = range,
col_names = col_names, col_types = col_types,
na = na, trim_ws = trim_ws, skip = skip,
n_max = n_max, guess_max = guess_max,
progress = progress,
.name_repair = .name_repair,
name_repair = name_repair,
format = "xls"
)
}
Expand All @@ -167,15 +186,24 @@
na = "", trim_ws = TRUE, skip = 0, n_max = Inf,
guess_max = min(1000, n_max),
progress = readxl_progress(),
.name_repair = "unique") {
name_repair = "unique",
.name_repair = deprecated()) {
path <- check_file(path)
if (lifecycle::is_present(.name_repair)) {
lifecycle::deprecate_warn(
"1.5.0",
"read_xlsx(.name_repair)",
"read_xlsx(name_repair)"
)
name_repair <- .name_repair

Check warning on line 198 in R/read_excel.R

View check run for this annotation

Codecov / codecov/patch

R/read_excel.R#L193-L198

Added lines #L193 - L198 were not covered by tests
}
read_excel_(
path = path, sheet = sheet, range = range,
col_names = col_names, col_types = col_types,
na = na, trim_ws = trim_ws, skip = skip,
n_max = n_max, guess_max = guess_max,
progress = progress,
.name_repair = .name_repair,
name_repair = name_repair,
format = "xlsx"
)
}
Expand All @@ -185,7 +213,7 @@
na = "", trim_ws = TRUE, skip = 0, n_max = Inf,
guess_max = min(1000, n_max),
progress = readxl_progress(),
.name_repair = NULL,
name_repair = NULL,
format) {
if (format == "xls") {
sheets_fun <- xls_sheets
Expand All @@ -212,7 +240,7 @@
na = na, trim_ws = trim_ws, guess_max = guess_max,
progress = progress
),
.name_repair = .name_repair
name_repair = name_repair
)
}

Expand Down Expand Up @@ -339,10 +367,10 @@
guess_max
}

set_readxl_names <- function(l, .name_repair = "unique") {
if (is.null(.name_repair)) {
set_readxl_names <- function(l, name_repair = "unique") {
if (is.null(name_repair)) {
tibble::as_tibble(l)
} else {
tibble::as_tibble(l, .name_repair = .name_repair)
tibble::as_tibble(l, .name_repair = name_repair)
}
}
1 change: 1 addition & 0 deletions R/readxl-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"_PACKAGE"

## usethis namespace: start
#' @importFrom lifecycle deprecated
## usethis namespace: end
NULL
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ We also have some focused articles that address specific aggravations presented

* Discovers the minimal data rectangle and returns that, by default. User can exert more control with `range`, `skip`, and `n_max`.

* Column names and types are determined from the data in the sheet, by default. User can also supply via `col_names` and `col_types` and control name repair via `.name_repair`.
* Column names and types are determined from the data in the sheet, by default. User can also supply via `col_names` and `col_types` and control name repair via `name_repair`.

* Returns a [tibble](https://tibble.tidyverse.org/reference/tibble.html), i.e. a data frame with an additional `tbl_df` class. Among other things, this provide nicer printing.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ presented by the world’s spreadsheets:

- Column names and types are determined from the data in the sheet, by
default. User can also supply via `col_names` and `col_types` and
control name repair via `.name_repair`.
control name repair via `name_repair`.

- Returns a
[tibble](https://tibble.tidyverse.org/reference/tibble.html), i.e. a
Expand Down
21 changes: 21 additions & 0 deletions man/figures/lifecycle-deprecated.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions man/figures/lifecycle-experimental.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions man/figures/lifecycle-stable.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions man/figures/lifecycle-superseded.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 15 additions & 10 deletions man/read_excel.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading