diff --git a/R/data_merge.R b/R/data_merge.R index 60d171007..d16959393 100644 --- a/R/data_merge.R +++ b/R/data_merge.R @@ -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)) } ) @@ -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) } } @@ -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)) diff --git a/tests/testthat/helper-state.R b/tests/testthat/helper-state.R new file mode 100644 index 000000000..f4c714c8e --- /dev/null +++ b/tests/testthat/helper-state.R @@ -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() + + # 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] + + list( + attached = search(), + connections = nrow(showConnections()), + cwd = getwd(), + envvars = Sys.getenv(), + libpaths = .libPaths(), + locale = Sys.getlocale(), + options = options, + packages = .packages(all.available = TRUE), + NULL + ) +})