Questions tagged [testthat]

testthat is a testing tool for R.

testthat is an package for , which is inspired by the family of testing packages and various testing libraries.

Repositories

Other resources

Related tags

366 questions
0
votes
1 answer

Capture warnings and assign a value in one go?

I am running some unit tests using the testthat package. I have a function that is tested repeatedly under various conditions. My problem is that the function has three kinds of "outputs": Prints to the console. This should be discarded. Elicits a…
Jonas Lindeløv
  • 5,442
  • 6
  • 31
  • 54
0
votes
1 answer

devtools::test() works, but devtools::check() fails when testing `expect_known_value()`

I am building unit tests for an R-package that I am developing. I am using testthat, and for some of the functions, I am using testthat::expect_known_value() I am saving the reference files created by expect_known_value() in a folder inside the…
Steen Harsted
  • 1,802
  • 2
  • 21
  • 34
0
votes
1 answer

Install all packages used in testing suite in R?

I'm trying to submit a PR to library(broom) which relies on testing a bunch of different libraries. Is there a quick way to install all the packages used in the testing suite?
dylanjm
  • 2,011
  • 9
  • 21
0
votes
0 answers

Compare() of two variables returns 'Equal' but identical() returns FALSE

Suppose you declared following function: compound <- function(x,i,t) { x*(1+i)^t } What are the fundamentals of following results: compare(compound(100, 0.1, 2),121) => 'Equal' and identical(compound(100, 0.1, 2),121) => FALSE In the package…
taddoo
  • 1
0
votes
0 answers

Unit tests for R functions that are not exported

I am quite new to unit testing, and I would like to implement some simple unit tests for the functions of an R package. The problem is that most functions of this R package are currently not exported, so that most of unit tests will concern R…
Philopolis
  • 515
  • 4
  • 13
0
votes
2 answers

How to test a function within a function in R?

I would like to use the testthat package to test a function that is enclosed by another function. How can I test such a function? If this is not possible, how can I refactor the code so that testing objective_function is possible? Illustrative…
robust
  • 594
  • 5
  • 17
0
votes
0 answers

`devtools::test()`, `RNGversion`, and `sample` yields different results

Below I present an issue I have with Rstudio's test feature. It is a simplified version of what I do in a package. I surely have done something wrong but I cannot figure out what. I discovered it when I started to make changes on a package on CRAN.…
0
votes
1 answer

How to test for specific warning(s), as produced by "warnings()"?

The problem I'm using the read_delim function to read in a lot of csv files (non-comma delimited). This produces warnings because some of the columns have the same name. I don't want to edit the original files, and I cannot change the column names…
Willem
  • 976
  • 9
  • 24
0
votes
0 answers

With testthat, where to place a custom skip function?

Where to place this function: skip_on_any <- function() { skip_on_cran() skip_on_travis() skip_on_appveyor() skip_on_bioc() } So that I can use it within any of my test files.
Ramiro Magno
  • 3,085
  • 15
  • 30
0
votes
0 answers

R testthat overwrite internal base functions

I'm writing a package which compares requested packages to available packages. That is, I can ask for 'mgsub == 1.5.0' and I want to see if I already have that version of a package installed before taking any action. I'm determining the already…
Mark
  • 4,387
  • 2
  • 28
  • 48
0
votes
0 answers

Run all the tests that are in sub directories in a unique file using testthat

When we use testthat in R, the package looks in tests/testthat directory and execute all the files that starts with 'test'... but if i have this type of…
0
votes
0 answers

How to check if a try error happened (possibly using testthat) when it is not desired to return the error value?

I want the function to produce an error in a try block if a condition is faced, and output one of the inputs without any change in the case of this error. Please note that I do not wish to create a list output or anything as I need to have…
aljabadi
  • 463
  • 4
  • 16
0
votes
0 answers

Add testthat to project using magrittr

I have an legacy project that doesn't uses namespaces. When I add testthat package it seams that it shadows some functions from magrittr package, especially magrittr::equals. I use roxygen to import packages, and import in comments only magrittr…
0
votes
3 answers

Acessing data on `inst/extdata` from Rcpp Catch tests

I am trying to access a data file on a inst/extdata file from a Rcpp Catch2 test. The file tree looks like this: ├── inst │   └── extdata │   └── data-sample ├── R │   ├── catch-routine-registration.R │   └── RcppExports.R ├── src    ├──…
Yuri-M-Dias
  • 610
  • 1
  • 11
  • 25
0
votes
1 answer

Is it possible to use testthat::expect_output to expect a carriage return?

I'm trying to test my package to ensure that a message printed to the screen ends in a carriage return. When I try to match the carriage return at the end, it never succeeds. is there a way to match the carriage return? library(testthat) foo <-…
Bill Denney
  • 766
  • 1
  • 6
  • 21