testthat

Why does testthat 2.3.2 use a different sort()

感情迁移 提交于 2020-11-29 04:47:26
问题 (This question is also asked at Github here) After an upgrade of R to 4.0.2 tests fail because it seems, the algorithm of sort in testthat changed. The following shows, that base::sort() and browser() are fine in R 4.0.2 (See this question, why this check is added.): y <- c("Schaffhausen", "Schwyz", "Seespital", "SRZ") print(sort(y)) # [1] "Schaffhausen" "Schwyz" "Seespital" "SRZ" browser() print(sort(y)) # [1] "Schaffhausen" "Schwyz" "Seespital" "SRZ" But if you create a package, call it

Testing conditions on a function's parameter using testthat

孤街浪徒 提交于 2020-07-22 06:07:08
问题 I have a function of the form func(expr, data.sizes) , where the parameter expr is an expression and the one named data.sizes is ordinarily as the name suggests, a vector or sequence of data sizes. (eg: c(10, 100, 1000) or 10^seq(1, 3) ) I would like to write some test-cases for my function's parameters using testthat , but am new to unit-testing in R so I would like to know how does one test conditions for a function's parameter(s) using testthat ? For instance, I want to check for a

r - data.table and testthat package

谁说我不能喝 提交于 2020-01-11 04:54:29
问题 I am building a package which works with data.table and which should be tested using package testthat. While the code works fine when calling from the command line, I run into issues when calling from a test case. It seems that the [] function from the base package, i.e. the function for data.frames is used when running the tests. I have created a minimum example which can be found here: https://github.com/utalo/test_datatable_testthat The package contains a single function: test <- function(

Include tests in binary R package

夙愿已清 提交于 2020-01-02 03:26:05
问题 I am using testthat to write unit tests for my R packages. I have seen a few package authors (like those from Rcpp and ggplot2 ) distributing their unit tests with the binary files. However, when I build my packages with RStudio (0.98.1102) and devtools (1.7.0) the tests folder is not included in the zip file. Do I have to add the folder manually or is it possible to get this done automatically by setting some option? BTW: I am on a Win7 machine using R v3.1.2 and RTools v3.1.0.1942. 回答1: Ha!

How to make devtools::test() consider package dependencies

喜夏-厌秋 提交于 2019-12-24 02:23:14
问题 Actual question Seems like devtools::test() does not make sure that package dependencies as stated in a package's DESCRIPTION file are loaded prior to running the unit tests. How can I change that? Details I'm writing a package ( B ) that imports another one of my packages ( A ). When I try to run my unit tests via devtools::test() , or, to be more precise via the shortcut SHFT + CRTL + T in RStudio, certain tests fail as the imported package seems to be disregarded/not loaded and thus a

R - testthat using data file outside the testing directory

百般思念 提交于 2019-12-23 07:27:25
问题 I am using testthat to test a package with a file tree similar to the following: . ├── data │ └── testhaplom.out ├── inst │ └── test │ ├── test1.r │ ├── tmp_S7byVksGRI6Q │ │ └── testm.desc │ └── tmp_vBcIkMN1arbn │ ├──testm.bin │ └── testm.desc ├── R │ ├── haplom.r │ └── winIdx.r └── tmp_eUG3Qb0PKuiN └── testhaplom.hap2.desc In the test1.r file, I need to use the data/testhaplom.out file as input data for a certain function, but if I do test_file(test1.r) , it changes into the inst/test

R testthat unit test data and helper function conventions

和自甴很熟 提交于 2019-12-21 07:01:31
问题 I am writing a R package, and I'm using testthat for unit testing. Many of my unit tests are for testing functions that work on a certain object specific to my package. For these tests I have made a helper function to set up a mock object. I have a few other helper functions as well to cut down the amount of code in my unit tests. Currently these helper functions are in my R/ folder, because then they become available to my unit test files (which are in tests/testthat/ ). I find it a bit

How to setup testthat for R CMD check?

本小妞迷上赌 提交于 2019-12-20 11:28:08
问题 There are apparently two ways to integrate testthat with R CMD check . I can't get either to work. Approach #1: (perhaps deprecated) According to the devtools wiki: When developing a package, put your tests in inst/tests and then create a file tests/run-all.R (note that it must be a capital R), which contains the following code: library(testthat) library(mypackage) test_package("mypackage") This will evaluate your tests in the package namespace (so you can test non-exported functions), and it

object no found error in testthat tests

核能气质少年 提交于 2019-12-20 06:00:59
问题 Here is the code: setGeneric("ifLet", function(sym, x, body1, body2, ...) { standardGeneric("ifLet") }) #' @name ifLet #' @export setMethod("ifLet", signature(sym = "name", x = "ANY", body1 = "ANY", body2 = "ANY"), function(sym, x, body1, body2 = {}) { e = new.env() sym_str = deparse(substitute(sym)) ifLet(sym_str, x, body1, body2) }) #' @rdname ifLet #' @export setMethod("ifLet", signature(sym = "character", x = "ANY", body1 = "ANY", body2 = "ANY"), function(sym, x, body1, body2 = {}) {

object no found error in testthat tests

情到浓时终转凉″ 提交于 2019-12-20 06:00:29
问题 Here is the code: setGeneric("ifLet", function(sym, x, body1, body2, ...) { standardGeneric("ifLet") }) #' @name ifLet #' @export setMethod("ifLet", signature(sym = "name", x = "ANY", body1 = "ANY", body2 = "ANY"), function(sym, x, body1, body2 = {}) { e = new.env() sym_str = deparse(substitute(sym)) ifLet(sym_str, x, body1, body2) }) #' @rdname ifLet #' @export setMethod("ifLet", signature(sym = "character", x = "ANY", body1 = "ANY", body2 = "ANY"), function(sym, x, body1, body2 = {}) {