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

Make coerce_to_numeric() internal #226

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5428ad6
Remove `coerce_to_numeric()`
IndrajeetPatil Aug 20, 2022
4d1dcfb
Merge branch 'main' into 206_rm_coerce_to_numeric
IndrajeetPatil Aug 21, 2022
17fc825
Merge branch 'main' into 206_rm_coerce_to_numeric
IndrajeetPatil Aug 21, 2022
277b2bb
Merge branch 'main' into 206_rm_coerce_to_numeric
strengejacke Aug 21, 2022
2d7e441
make `coerce_to_numeric()` internal
strengejacke Aug 21, 2022
c5e9357
Merge branch 'main' into 206_rm_coerce_to_numeric
IndrajeetPatil Aug 21, 2022
1340fb5
Merge branch 'main' into 206_rm_coerce_to_numeric
IndrajeetPatil Aug 21, 2022
19cff58
Merge branch 'main' into 206_rm_coerce_to_numeric
strengejacke Aug 22, 2022
2fb5cd2
Merge branch 'main' into 206_rm_coerce_to_numeric
IndrajeetPatil Aug 24, 2022
e9ab70f
Merge branch 'main' into 206_rm_coerce_to_numeric
IndrajeetPatil Aug 24, 2022
67e255d
Merge branch 'main' into 206_rm_coerce_to_numeric
IndrajeetPatil Aug 24, 2022
d866b1d
Merge branch 'main' into 206_rm_coerce_to_numeric
IndrajeetPatil Aug 25, 2022
9b5ce47
Merge branch 'main' into 206_rm_coerce_to_numeric
IndrajeetPatil Aug 25, 2022
c4c88c4
Merge branch 'main' into 206_rm_coerce_to_numeric
IndrajeetPatil Aug 31, 2022
daa7f64
Merge branch 'main' into 206_rm_coerce_to_numeric
IndrajeetPatil Sep 1, 2022
d15794c
Merge branch 'main' into 206_rm_coerce_to_numeric
IndrajeetPatil Sep 2, 2022
5b9e4e1
Merge branch 'main' into 206_rm_coerce_to_numeric
IndrajeetPatil Sep 15, 2022
a25dc06
Fix build failures
IndrajeetPatil Sep 15, 2022
481bd84
Merge branch 'main' into 206_rm_coerce_to_numeric
IndrajeetPatil Sep 19, 2022
3be4e41
Merge branch 'main' into 206_rm_coerce_to_numeric
strengejacke Oct 27, 2022
1bc807d
use interal
strengejacke Oct 27, 2022
976c2b2
Merge branch 'main' into 206_rm_coerce_to_numeric
strengejacke Oct 27, 2022
83d0a8b
Merge branch 'main' into 206_rm_coerce_to_numeric
strengejacke Dec 10, 2022
521489a
Merge branch 'main' into 206_rm_coerce_to_numeric
IndrajeetPatil Dec 28, 2022
504fd2b
Merge branch 'main' into 206_rm_coerce_to_numeric
IndrajeetPatil Dec 28, 2022
7d73626
Merge branch 'main' into 206_rm_coerce_to_numeric
IndrajeetPatil Jan 2, 2023
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
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ export(centre)
export(change_code)
export(change_scale)
export(coef_var)
export(coerce_to_numeric)
export(colnames_to_row)
export(column_as_rownames)
export(compact_character)
Expand Down
7 changes: 3 additions & 4 deletions R/data_restoretype.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
#' fixed <- data_restoretype(data, reference = iris)
#' summary(fixed)
#' @export

data_restoretype <- function(data, reference = NULL, ...) {
for (col in names(data)) {
# No reference data (regular fixing) ----------------
if (is.null(reference)) {
if (is.character(data[[col]])) {
data[[col]] <- coerce_to_numeric(data[[col]])
data[[col]] <- .coerce_to_numeric(data[[col]])
}
} else {
if (is.factor(reference[[col]]) && !is.factor(data[[col]])) {
Expand All @@ -36,11 +35,11 @@ data_restoretype <- function(data, reference = NULL, ...) {
}

if (is.numeric(reference[[col]]) && !is.numeric(data[[col]])) {
data[[col]] <- coerce_to_numeric(as.character(data[[col]]))
data[[col]] <- .coerce_to_numeric(as.character(data[[col]]))
}

if (is.character(reference[[col]]) && !is.character(data[[col]])) {
data[[col]] <- as.character(data[[col]])
data[[col]] <- .coerce_to_numeric(data[[col]])
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion R/data_to_long.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ data_to_long <- function(data,
# create a temp id so that we know how to rearrange the rows once the data is
# stacked
not_stacked <- data[, not_selected, drop = FALSE]
not_stacked[["_Rows"]] <- coerce_to_numeric(row.names(data))
not_stacked[["_Rows"]] <- .coerce_to_numeric(row.names(data))

# stack the selected columns
stacked_data <- .stack(data[, cols, drop = FALSE])[, 2:1]
Expand Down
16 changes: 2 additions & 14 deletions R/to_numeric.R
Original file line number Diff line number Diff line change
Expand Up @@ -266,20 +266,8 @@ to_numeric.character <- function(x,
}



#' Convert to Numeric (if possible)
#'
#' Tries to convert vector to numeric if possible (if no warnings or errors).
#' Otherwise, leaves it as is.
#'
#' @param x A vector to be converted.
#'
#' @examples
#' coerce_to_numeric(c("1", "2"))
#' coerce_to_numeric(c("1", "2", "A"))
#' @return Numeric vector (if possible)
#' @export
coerce_to_numeric <- function(x) {
#' @keywords internal
.coerce_to_numeric <- function(x) {
tryCatch(as.numeric(as.character(x)),
error = function(e) x,
warning = function(w) x
Expand Down
22 changes: 0 additions & 22 deletions man/coerce_to_numeric.Rd

This file was deleted.