Skip to content

Commit

Permalink
Remove coerce_to_numeric()
Browse files Browse the repository at this point in the history
Closes #206
  • Loading branch information
IndrajeetPatil committed Aug 20, 2022
1 parent cbcf7f2 commit 5428ad6
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 46 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ export(center)
export(centre)
export(change_code)
export(change_scale)
export(coerce_to_numeric)
export(colnames_to_row)
export(column_as_rownames)
export(compact_character)
Expand Down
2 changes: 1 addition & 1 deletion R/data_reshape.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ data_to_long <- function(data,

# Reshaping ---------------------
# Create Index column as needed by reshape
data[["_Row"]] <- coerce_to_numeric(row.names(data))
data[["_Row"]] <- as.numeric(row.names(data))

# Create a new index for cases with length(names_to) > 1
names_to_2 <- paste(names_to, collapse = "_")
Expand Down
4 changes: 2 additions & 2 deletions R/data_restoretype.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ data_restoretype <- function(data, reference = NULL, ...) {
# No reference data (regular fixing) ----------------
if (is.null(reference)) {
if (is.character(data[[col]])) {
data[[col]] <- coerce_to_numeric(data[[col]])
data[[col]] <- as.numeric(data[[col]])
}
} else {
if (is.factor(reference[[col]]) && !is.factor(data[[col]])) {
Expand All @@ -35,7 +35,7 @@ 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]] <- as.numeric(as.character(data[[col]]))
}

if (is.character(reference[[col]]) && !is.character(data[[col]])) {
Expand Down
20 changes: 0 additions & 20 deletions R/to_numeric.R
Original file line number Diff line number Diff line change
Expand Up @@ -251,23 +251,3 @@ to_numeric.character <- function(x,
out
}



#' 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) {
tryCatch(as.numeric(as.character(x)),
error = function(e) x,
warning = function(w) x
)
}
22 changes: 0 additions & 22 deletions man/coerce_to_numeric.Rd

This file was deleted.

0 comments on commit 5428ad6

Please sign in to comment.