Skip to content

Commit

Permalink
lintr, styler
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher committed May 18, 2024
1 parent a7be7f3 commit 633f155
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 54 deletions.
46 changes: 23 additions & 23 deletions R/center.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,21 @@ center.numeric <- function(x,
center <- TRUE
}

args <- .process_std_center(x, weights, robust, verbose, reference, center, scale = NULL)
my_args <- .process_std_center(x, weights, robust, verbose, reference, center, scale = NULL)
dot_args <- list(...)

if (is.null(args)) {
if (is.null(my_args)) {
# all NA?
return(x)
} else if (is.null(args$check)) {
vals <- rep(0, length(args$vals)) # If only unique value
} else if (is.null(my_argscheck)) {
vals <- rep(0, length(my_argsvals)) # If only unique value
} else {
vals <- as.vector(args$vals - args$center)
vals <- as.vector(my_argsvals - my_argscenter)
}

centered_x <- rep(NA, length(args$valid_x))
centered_x[args$valid_x] <- vals
attr(centered_x, "center") <- args$center
centered_x <- rep(NA, length(my_argsvalid_x))
centered_x[my_argsvalid_x] <- vals
attr(centered_x, "center") <- my_argscenter
attr(centered_x, "scale") <- 1
attr(centered_x, "robust") <- robust
# labels
Expand Down Expand Up @@ -197,29 +197,29 @@ center.data.frame <- function(x,
)

# process arguments
args <- .process_std_args(x, select, exclude, weights, append,
my_args <- .process_std_args(x, select, exclude, weights, append,
append_suffix = "_c", keep_factors = force, remove_na, reference,
.center = center, .scale = NULL
)

# set new values
x <- args$x
x <- my_args$x

for (var in args$select) {
for (var in my_args$select) {
x[[var]] <- center(
x[[var]],
robust = robust,
weights = args$weights,
weights = my_args$weights,
verbose = FALSE,
reference = reference[[var]],
center = args$center[var],
center = my_args$center[var],
force = force,
add_transform_class = FALSE
)
}

attr(x, "center") <- vapply(x[args$select], function(z) attributes(z)$center, numeric(1))
attr(x, "scale") <- vapply(x[args$select], function(z) attributes(z)$scale, numeric(1))
attr(x, "center") <- vapply(x[my_args$select], function(z) attributes(z)$center, numeric(1))
attr(x, "scale") <- vapply(x[my_args$select], function(z) attributes(z)$scale, numeric(1))
attr(x, "robust") <- robust
x
}
Expand Down Expand Up @@ -249,19 +249,19 @@ center.grouped_df <- function(x,
verbose = verbose
)

args <- .process_grouped_df(
my_args <- .process_grouped_df(
x, select, exclude, append,
append_suffix = "_c",
reference, weights, keep_factors = force
)

for (rows in args$grps) {
args$x[rows, ] <- center(
args$x[rows, , drop = FALSE],
select = args$select,
for (rows in my_args$grps) {
my_args$x[rows, ] <- center(
my_args$x[rows, , drop = FALSE],
select = my_args$select,
exclude = NULL,
robust = robust,
weights = args$weights,
weights = my_args$weights,
remove_na = remove_na,
verbose = verbose,
force = force,
Expand All @@ -272,8 +272,8 @@ center.grouped_df <- function(x,
)
}
# set back class, so data frame still works with dplyr
attributes(args$x) <- args$info
args$x
attributes(my_args$x) <- my_args$info
my_args$x
}


Expand Down
4 changes: 2 additions & 2 deletions R/convert_na_to.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ convert_na_to.data.frame <- function(x,
regex = FALSE,
verbose = TRUE,
...) {
data <- x
my_data <- x
select_nse <- .select_nse(
select,
data,
data = my_data,
exclude = exclude,
ignore_case,
regex = regex,
Expand Down
16 changes: 8 additions & 8 deletions R/data_group.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,26 @@ data_group <- function(data,
verbose = verbose
)
# create grid with combinations of all levels
grid <- as.data.frame(expand.grid(lapply(data[select], unique)))
my_grid <- as.data.frame(expand.grid(lapply(data[select], unique)))
# sort grid
grid <- grid[do.call(order, grid), , drop = FALSE]
my_grid <- my_grid[do.call(order, my_grid), , drop = FALSE]

.rows <- lapply(seq_len(nrow(grid)), function(i) {
.rows <- lapply(seq_len(nrow(my_grid)), function(i) {
as.integer(data_match(
data,
to = grid[i, , drop = FALSE],
to = my_grid[i, , drop = FALSE],
match = "and",
return_indices = TRUE,
drop_na = FALSE
))
})
grid[[".rows"]] <- .rows
my_grid[[".rows"]] <- .rows

# remove data_match attributes
attr(grid, "out.attrs") <- NULL
attr(grid, ".drop") <- TRUE
attr(my_grid, "out.attrs") <- NULL
attr(my_grid, ".drop") <- TRUE

attr(data, "groups") <- grid
attr(data, "groups") <- my_grid
class(data) <- unique(c("grouped_df", "data.frame"), class(data))

data
Expand Down
2 changes: 2 additions & 0 deletions R/data_relocate.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ data_relocate <- function(data,
original_after <- after

# Find new positions
# nolint start
if (!is.null(before)) {
before <- before[before %in% data_cols][1] # Take first that exists (if vector is supplied)
if (length(before) != 1 || is.na(before)) {
Expand All @@ -123,6 +124,7 @@ data_relocate <- function(data,
where <- 1
position <- union(position, where)
}
# nolint end

# Set left and right side
lhs <- setdiff(seq(1, where - 1), position)
Expand Down
3 changes: 2 additions & 1 deletion R/data_rename.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
#' - Functions to rename stuff: [data_rename()], [data_rename_rows()], [data_addprefix()], [data_addsuffix()]
#' - Functions to reorder or remove columns: [data_reorder()], [data_relocate()], [data_remove()]
#' - Functions to reshape, pivot or rotate data frames: [data_to_long()], [data_to_wide()], [data_rotate()]
#' - Functions to recode data: [rescale()], [reverse()], [categorize()], [recode_values()], [slide()]
#' - Functions to recode data: [rescale()], [reverse()], [categorize()],
#' [recode_values()], [slide()]
#' - Functions to standardize, normalize, rank-transform: [center()], [standardize()], [normalize()], [ranktransform()], [winsorize()]

Check warning on line 48 in R/data_rename.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/data_rename.R,line=48,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 134 characters.

Check warning on line 48 in R/data_rename.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/data_rename.R,line=48,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 134 characters.
#' - Split and merge data frames: [data_partition()], [data_merge()]
#' - Functions to find or select columns: [data_select()], [extract_column_names()]
Expand Down
12 changes: 6 additions & 6 deletions R/data_rescale.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,16 @@ rescale.grouped_df <- function(x,
# create the new variables and updates "select", so new variables are processed
if (!isFALSE(append)) {
# process arguments
args <- .process_append(
my_args <- .process_append(
x,
select,
append,
append_suffix = "_r",
preserve_value_labels = TRUE
)
# update processed arguments
x <- args$x
select <- args$select
x <- my_args$x
select <- my_args$select
}

x <- as.data.frame(x)
Expand Down Expand Up @@ -263,15 +263,15 @@ rescale.data.frame <- function(x,
# create the new variables and updates "select", so new variables are processed
if (!isFALSE(append)) {
# process arguments
args <- .process_append(
my_args <- .process_append(
x,
select,
append,
append_suffix = "_r"
)
# update processed arguments
x <- args$x
select <- args$select
x <- my_args$x
select <- my_args$select
}

# Transform the range so that it is a list now
Expand Down
2 changes: 1 addition & 1 deletion R/select_nse.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
# 3 types of symbols:
# - unquoted variables
# - objects that need to be evaluated, e.g data_find(iris, i) where
# i is a function arg or is defined before. This can also be a
# i is a function arg or is defined before. This can also be a
# vector of names or positions.
# - functions (without parenthesis)

Expand Down
3 changes: 2 additions & 1 deletion man/categorize.Rd

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

3 changes: 2 additions & 1 deletion man/data_match.Rd

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

3 changes: 2 additions & 1 deletion man/data_merge.Rd

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

3 changes: 2 additions & 1 deletion man/data_partition.Rd

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

3 changes: 2 additions & 1 deletion man/data_relocate.Rd

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

3 changes: 2 additions & 1 deletion man/data_rename.Rd

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

3 changes: 2 additions & 1 deletion man/data_rotate.Rd

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

3 changes: 2 additions & 1 deletion man/data_to_long.Rd

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

Loading

0 comments on commit 633f155

Please sign in to comment.