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

Add testthat helper state #465

Merged
merged 10 commits into from
Jun 3, 2024
12 changes: 6 additions & 6 deletions R/data_merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ data_merge.data.frame <- function(x, y, join = "left", by = NULL, id = NULL, ver
missing_in_y <- setdiff(by, colnames(y))
stop_message <- c(
"Not all columns specified in `by` were found in the data frames.",
if (length(missing_in_x) > 0) {
if (length(missing_in_x) > 0L) {
paste0("Following columns are in `by` but absent in `x`: ", text_concatenate(missing_in_x))
},
if (length(missing_in_y) > 0) {
if (length(missing_in_y) > 0L) {
paste0("Following columns are in `by` but absent in `y`: ", text_concatenate(missing_in_y))
}
)
Expand Down Expand Up @@ -262,10 +262,10 @@ data_merge.data.frame <- function(x, y, join = "left", by = NULL, id = NULL, ver

# for later sorting
if (join != "bind") {
if (nrow(x) > 0) {
if (nrow(x) > 0L) {
x$.data_merge_id_x <- seq_len(nrow(x))
}
if (nrow(y) > 0) {
if (nrow(y) > 0L) {
y$.data_merge_id_y <- (seq_len(nrow(y))) + nrow(x)
}
}
Expand Down Expand Up @@ -362,10 +362,10 @@ data_merge.list <- function(x, join = "left", by = NULL, id = NULL, verbose = TR
out <- rbind(x, y[match(colnames(x), colnames(y))])
} else {
# add ID for merging
if (nrow(x) > 0) {
if (nrow(x) > 0L) {
x$.data_merge_row <- seq_len(nrow(x))
}
if (nrow(y) > 0) {
if (nrow(y) > 0L) {
y$.data_merge_row <- (nrow(x) + 1):(nrow(x) + nrow(y))
}
merge_by <- intersect(colnames(x), colnames(y))
Expand Down
48 changes: 48 additions & 0 deletions tests/testthat/helper-state.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
testthat::set_state_inspector(function() {
# sometimes a dependency might add a custom option, so we need to
# make sure we don't fail because of such additions
options <- options()

Check warning on line 4 in tests/testthat/helper-state.R

View workflow job for this annotation

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

file=tests/testthat/helper-state.R,line=4,col=3,[object_overwrite_linter] 'options' is an exported object from package 'base'. Avoid re-using such symbols.

# Result of `dput(names(options()))`
base_options <- c(
"add.smooth", "askpass", "asksecret", "bitmapType", "browser",
"browserNLdisabled", "buildtools.check", "buildtools.with", "callr.condition_handler_cli_message",
"CBoundsCheck", "check.bounds", "citation.bibtex.max", "connectionObserver",
"continue", "contrasts", "defaultPackages", "demo.ask", "deparse.cutoff",
"deparse.max.lines", "device", "device.ask.default", "digits",
"download.file.method", "dvipscmd", "echo", "editor", "encoding",
"example.ask", "expressions", "ggvis.renderer", "help_type",
"help.search.types", "help.try.all.packages", "HTTPUserAgent",
"install.packages.compile.from.source", "internet.info", "keep.parse.data",
"keep.parse.data.pkgs", "keep.source", "keep.source.pkgs", "locatorBell",
"mailer", "matprod", "max.contour.segments", "max.print", "menu.graphics",
"na.action", "nwarnings", "OutDec", "page_viewer", "pager", "papersize",
"PCRE_limit_recursion", "PCRE_study", "PCRE_use_JIT", "pdfviewer",
"pkgType", "plumber.docs.callback", "plumber.swagger.url", "printcmd",
"profvis.keep_output", "profvis.print", "profvis.prof_extension",
"profvis.prof_output", "prompt", "repos", "restart", "reticulate.initialized",
"reticulate.repl.busy", "reticulate.repl.hook", "reticulate.repl.initialize",
"reticulate.repl.teardown", "rl_word_breaks", "rsconnect.check.certificate",
"rstudio.notebook.executing", "RStudioGD.antialias", "RStudioGD.backend",
"scipen", "shiny.launch.browser", "shinygadgets.showdialog",
"show.coef.Pvalues", "show.error.messages", "show.signif.stars",
"showErrorCalls", "showNCalls", "showWarnCalls", "str", "str.dendrogram.last",
"terminal.manager", "texi2dvi", "timeout", "ts.eps", "ts.S.compat",
"unzip", "useFancyQuotes", "verbose", "viewer", "warn", "warning.length",
"warnPartialMatchArgs", "warnPartialMatchAttr", "warnPartialMatchDollar",
"width"
)
options <- options[base_options]

Check warning on line 35 in tests/testthat/helper-state.R

View workflow job for this annotation

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

file=tests/testthat/helper-state.R,line=35,col=3,[object_overwrite_linter] 'options' is an exported object from package 'base'. Avoid re-using such symbols.

list(
attached = search(),
connections = nrow(showConnections()),
cwd = getwd(),
envvars = Sys.getenv(),
libpaths = .libPaths(),
locale = Sys.getlocale(),
options = options,
packages = .packages(all.available = TRUE),
NULL
)
})
Loading