Skip to content

Commit

Permalink
address keyword_quote_linter() lints
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil committed Oct 6, 2023
1 parent 427127c commit 6c3bcf5
Show file tree
Hide file tree
Showing 18 changed files with 120 additions and 107 deletions.
10 changes: 5 additions & 5 deletions R/categorize.R
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ categorize.numeric <- function(x,
breaks <- split
} else {
breaks <- switch(split,
"median" = stats::median(x),
"mean" = mean(x),
"length" = n_groups,
"quantile" = stats::quantile(x, probs = seq_len(n_groups) / n_groups),
"range" = .equal_range(x, range, n_groups, lowest),
median = stats::median(x),
mean = mean(x),
length = n_groups,
quantile = stats::quantile(x, probs = seq_len(n_groups) / n_groups),
range = .equal_range(x, range, n_groups, lowest),
NULL
)
}
Expand Down
10 changes: 8 additions & 2 deletions R/data_codebook.R
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,14 @@ print_md.data_codebook <- function(x, ...) {
# need to remove this one
x$Prop <- NULL
align <- c(
"ID" = "l", "Name" = "l", "Label" = "l", "Type" = "l", "Missings" = "r",
"Values" = "r", "Value Labels" = "l", "N" = "r"
ID = "l",
Name = "l",
Label = "l",
Type = "l",
Missings = "r",
Values = "r",
`Value Labels` = "l",
N = "r"
)
align <- align[colnames(x)]
paste0(unname(align), collapse = "")
Expand Down
8 changes: 4 additions & 4 deletions R/data_extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ data_extract.data.frame <- function(data,

# chose which matched variables to extract
select <- switch(extract,
"first" = select[1L],
"last" = select[length(select)],
"odd" = select[seq(1L, length(select), 2L)],
"even" = select[seq(2L, length(select), 2L)],
first = select[1L],
last = select[length(select)],
odd = select[seq(1L, length(select), 2L)],
even = select[seq(2L, length(select), 2L)],
select
)

Expand Down
13 changes: 6 additions & 7 deletions R/data_match.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,17 @@ data_match <- function(x, to, match = "and", return_indices = FALSE, drop_na = T
# evaluate
match <- match.arg(tolower(match), c("and", "&", "&&", "or", "|", "||", "!", "not"))
match <- switch(match,
"&" = ,
"&&" = ,
"and" = "and",
"!" = ,
"not" = "not",
`&` = ,
`&&` = ,
and = "and",
`!` = ,
not = "not",
"or"
)

# validation check
shared_columns <- intersect(colnames(x), colnames(to))
if (is.null(shared_columns) || length(shared_columns) == 0) {
if (is.null(shared_columns) || length(shared_columns) == 0L) {
insight::format_error(
"None of the columns from the data frame with matching conditions were found in `x`."
)
Expand Down Expand Up @@ -277,7 +277,6 @@ data_filter.data.frame <- function(x, ...) {

#' @export
data_filter.grouped_df <- function(x, ...) {
# works only for dplyr >= 0.8.0
grps <- attr(x, "groups", exact = TRUE)
grps <- grps[[".rows"]]

Expand Down
14 changes: 7 additions & 7 deletions R/data_merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,13 @@ data_merge.data.frame <- function(x, y, join = "left", by = NULL, id = NULL, ver
all_columns <- union(colnames(x), colnames(y))

out <- switch(join,
"full" = merge(x, y, all = TRUE, sort = FALSE, by = by),
"left" = merge(x, y, all.x = TRUE, sort = FALSE, by = by),
"right" = merge(x, y, all.y = TRUE, sort = FALSE, by = by),
"inner" = merge(x, y, sort = FALSE, by = by),
"semi" = x[x[[by]] %in% y[[by]], , drop = FALSE],
"anti" = x[!x[[by]] %in% y[[by]], , drop = FALSE],
"bind" = .bind_data_frames(x, y)
full = merge(x, y, all = TRUE, sort = FALSE, by = by),
left = merge(x, y, all.x = TRUE, sort = FALSE, by = by),
right = merge(x, y, all.y = TRUE, sort = FALSE, by = by),
inner = merge(x, y, sort = FALSE, by = by),
semi = x[x[[by]] %in% y[[by]], , drop = FALSE],
anti = x[!x[[by]] %in% y[[by]], , drop = FALSE],
bind = .bind_data_frames(x, y)
)


Expand Down
16 changes: 8 additions & 8 deletions R/data_read.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ data_read <- function(path,

# read data
out <- switch(file_type,
"txt" = ,
"csv" = .read_text(path, encoding, verbose, ...),
"xls" = ,
"xlsx" = .read_excel(path, encoding, verbose, ...),
"sav" = ,
"por" = .read_spss(path, encoding, convert_factors, verbose, ...),
"dta" = .read_stata(path, encoding, convert_factors, verbose, ...),
"sas7bdat" = .read_sas(path, path_catalog, encoding, convert_factors, verbose, ...),
txt = ,
csv = .read_text(path, encoding, verbose, ...),
xls = ,
xlsx = .read_excel(path, encoding, verbose, ...),
sav = ,
por = .read_spss(path, encoding, convert_factors, verbose, ...),
dta = .read_stata(path, encoding, convert_factors, verbose, ...),
sas7bdat = .read_sas(path, path_catalog, encoding, convert_factors, verbose, ...),
.read_unknown(path, convert_factors, verbose, ...)
)

Expand Down
22 changes: 11 additions & 11 deletions R/data_separate.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ data_separate <- function(data,
l <- l[!vapply(l, function(i) all(is.na(i)), TRUE)]
# define number of new columns, based on user-choice
n_cols <- switch(guess_columns,
"min" = min(l, na.rm = TRUE),
"max" = max(l, na.rm = TRUE),
"mode" = distribution_mode(l),
min = min(l, na.rm = TRUE),
max = max(l, na.rm = TRUE),
mode = distribution_mode(l),
)
# tell user
if (verbose && insight::n_unique(l) != 1 && !is.numeric(separator)) {
Expand Down Expand Up @@ -374,10 +374,10 @@ data_separate <- function(data,
"`", sep_column, "`",
" returned more columns than expected after splitting. ",
switch(extra,
"drop_left" = "Left-most columns have been dropped.",
"drop_right" = "Right-most columns have been dropped.",
"merge_left" = "Left-most columns have been merged together.",
"merge_right" = "Right-most columns have been merged together."
drop_left = "Left-most columns have been dropped.",
drop_right = "Right-most columns have been dropped.",
merge_left = "Left-most columns have been merged together.",
merge_right = "Right-most columns have been merged together."
)
))
}
Expand All @@ -386,10 +386,10 @@ data_separate <- function(data,
"`", sep_column, "`",
"returned fewer columns than expected after splitting. ",
switch(fill,
"left" = "Left-most columns were filled with `NA`.",
"right" = "Right-most columns were filled with `NA`.",
"value_left" = "Left-most columns were filled with first value.",
"value_right" = "Right-most columns were filled with last value."
left = "Left-most columns were filled with `NA`.",
right = "Right-most columns were filled with `NA`.",
value_left = "Left-most columns were filled with first value.",
value_right = "Right-most columns were filled with last value."
)
))
}
Expand Down
16 changes: 8 additions & 8 deletions R/data_tabulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -489,14 +489,14 @@ print_md.dw_data_tabulates <- function(x, big_mark = NULL, ...) {
}

switch(vt,
"ord" = "ordinal",
"fct" = "categorical",
"dbl" = "numeric",
"int" = "integer",
"chr" = "character",
"lbl" = "labelled",
"cpl" = "complex",
"lgl" = "logical",
ord = "ordinal",
fct = "categorical",
dbl = "numeric",
int = "integer",
chr = "character",
lbl = "labelled",
cpl = "complex",
lgl = "logical",
vt
)
}
14 changes: 7 additions & 7 deletions R/data_write.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ data_write <- function(data,
# check file type, so we know the target dta format
file_type <- .file_ext(path)
type <- switch(file_type,
"txt" = ,
"csv" = "csv",
"sav" = ,
"por" = "spss",
"zsav" = "zspss",
"dta" = "stata",
"xpt" = "sas",
txt = ,
csv = "csv",
sav = ,
por = "spss",
zsav = "zspss",
dta = "stata",
xpt = "sas",
"unknown"
)

Expand Down
2 changes: 1 addition & 1 deletion R/describe_distribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ describe_distribution.numeric <- function(x,

out$n <- length(x)
out$n_Missing <- n_missing
out$`.temp` <- NULL
out$.temp <- NULL

class(out) <- unique(c("parameters_distribution", "see_parameters_distribution", class(out)))
attr(out, "data") <- x
Expand Down
32 changes: 16 additions & 16 deletions R/select_nse.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@
type <- typeof(x)

out <- switch(type,
"integer" = x,
"double" = as.integer(x),
"character" = .select_char(data, x, ignore_case, regex = regex, verbose),
"symbol" = .select_symbol(data, x, ignore_case, regex = regex, verbose),
"language" = .eval_call(data, x, ignore_case, regex = regex, verbose),
integer = x,
double = as.integer(x),
character = .select_char(data, x, ignore_case, regex = regex, verbose),
symbol = .select_symbol(data, x, ignore_case, regex = regex, verbose),
language = .eval_call(data, x, ignore_case, regex = regex, verbose),
insight::format_error(paste0(
"Expressions of type <", typeof(x),
"> cannot be evaluated for use when subsetting."
Expand Down Expand Up @@ -254,13 +254,13 @@
`[` = .select_square_bracket(x, data, ignore_case, regex, verbose),
`$` = .select_dollar(x, data, ignore_case, regex, verbose),
`~` = .select_tilde(x, data, ignore_case, regex, verbose),
"list" = .select_list(x, data, ignore_case, regex, verbose),
"names" = .select_names(x, data, ignore_case, regex, verbose),
"starts_with" = ,
"ends_with" = ,
"matches" = ,
"contains" = ,
"regex" = .select_helper(x, data, ignore_case, regex, verbose),
list = .select_list(x, data, ignore_case, regex, verbose),
names = .select_names(x, data, ignore_case, regex, verbose),
starts_with = ,
ends_with = ,
matches = ,
contains = ,
regex = .select_helper(x, data, ignore_case, regex, verbose),
.select_context(x, data, ignore_case, regex, verbose)
)
}
Expand Down Expand Up @@ -369,10 +369,10 @@
helper <- insight::safe_deparse(lst_expr[[1]])

rgx <- switch(helper,
"starts_with" = paste0("^(", collapsed_patterns, ")"),
"ends_with" = paste0("(", collapsed_patterns, ")$"),
"contains" = paste0("(", collapsed_patterns, ")"),
"regex" = collapsed_patterns,
starts_with = paste0("^(", collapsed_patterns, ")"),
ends_with = paste0("(", collapsed_patterns, ")$"),
contains = paste0("(", collapsed_patterns, ")"),
regex = collapsed_patterns,
insight::format_error("There is no select helper called '", helper, "'.")
)
grep(rgx, colnames(data), ignore.case = ignore_case)
Expand Down
20 changes: 10 additions & 10 deletions R/skewness_kurtosis.R
Original file line number Diff line number Diff line change
Expand Up @@ -474,16 +474,16 @@ summary.parameters_kurtosis <- function(object, test = FALSE, ...) {
}

switch(type,
"1" = ,
"I" = ,
"classic" = "1",
"2" = ,
"II" = ,
"SPSS" = ,
"SAS" = "2",
"3" = ,
"III" = ,
"Minitab" = "3"
`1` = ,
I = ,
classic = "1",
`2` = ,
II = ,
SPSS = ,
SAS = "2",
`3` = ,
III = ,
Minitab = "3"
)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-assign_labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test_that("assign_labels, named values", {
out <- assign_labels(
x,
variable = "Labelled factor",
values = c(`a` = "low", `b` = "mid", `c` = "high")
values = c(a = "low", b = "mid", c = "high")
)
expect_identical(attributes(out)$label, "Labelled factor")
expect_identical(attributes(out)$labels, c(low = "a", mid = "b", high = "c"))
Expand Down
20 changes: 12 additions & 8 deletions tests/testthat/test-data_codebook.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ test_that("data_codebook, tagged NA", {
1:4, haven::tagged_na("a", "c", "z")
),
labels = c(
"Agreement" = 1, "Disagreement" = 4,
"First" = haven::tagged_na("c"), "Refused" = haven::tagged_na("a"),
"Not home" = haven::tagged_na("z")
Agreement = 1,
Disagreement = 4,
First = haven::tagged_na("c"),
Refused = haven::tagged_na("a"),
`Not home` = haven::tagged_na("z")
)
)
expect_snapshot(data_codebook(data.frame(x)))
Expand All @@ -174,9 +176,11 @@ test_that("data_codebook, tagged NA", {
1:4, haven::tagged_na("a", "c")
),
labels = c(
"Agreement" = 1, "Disagreement" = 4,
"First" = haven::tagged_na("c"), "Refused" = haven::tagged_na("a"),
"Not home" = haven::tagged_na("z")
Agreement = 1,
Disagreement = 4,
First = haven::tagged_na("c"),
Refused = haven::tagged_na("a"),
`Not home` = haven::tagged_na("z")
)
)
expect_snapshot(data_codebook(data.frame(x)))
Expand All @@ -187,11 +191,11 @@ test_that("data_codebook, negative label values #334", {
skip_if_not_installed("haven")
x1 <- haven::labelled(
x = 1:4,
labels = c("Agreement" = 1, "Disagreement" = 4, "Missing" = -9)
labels = c(Agreement = 1, Disagreement = 4, Missing = -9)
)
x2 <- haven::labelled(
x = c(1:3, -9),
labels = c("Agreement" = 1, "Disagreement" = 4, "Missing" = -9)
labels = c(Agreement = 1, Disagreement = 4, Missing = -9)
)
expect_snapshot(data_codebook(data.frame(x1, x2)))
})
6 changes: 3 additions & 3 deletions tests/testthat/test-data_merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ test_that("join data frames in a list", {

# join empty data frames -----------------------

x <- data.frame("x" = character(), stringsAsFactors = FALSE)
y <- data.frame("x" = character(), stringsAsFactors = FALSE)
z <- data.frame("y" = character(), stringsAsFactors = FALSE)
x <- data.frame(x = character(), stringsAsFactors = FALSE)
y <- data.frame(x = character(), stringsAsFactors = FALSE)
z <- data.frame(y = character(), stringsAsFactors = FALSE)

test_that("join empty data frames", {
expect_identical(dim(data_merge(x, y, join = "left")), c(0L, 1L))
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-data_rescale.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ test_that("rescale works as expected", {

expect_snapshot(
head(rescale(iris, to = list(
"Sepal.Length" = c(0, 1),
"Petal.Length" = c(-1, 0)
Sepal.Length = c(0, 1),
Petal.Length = c(-1, 0)
)))
)
})
Expand Down
Loading

0 comments on commit 6c3bcf5

Please sign in to comment.