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

unit test for xts with no row

is this a bug in package testthat? I would expect x to be always identical to x... Instead I get an error. x = structure(logical(0), index = structure(numeric(0), tzone = "", tclass = c("POSIXct", "POSIXt")), .indexCLASS = c("POSIXct", "POSIXt"),…
RockScience
  • 17,932
  • 26
  • 89
  • 125
0
votes
0 answers

Handling multiple warning (ggplot2) warnings with testthat while testing a Markdown script

I have created a markdown script which is producing some ggplot graphs. I also wrote a test script to automatically testing the whole markdown by first extracting the code chunks and then executing the script. With some test data, I get warnings…
drmariod
  • 11,106
  • 16
  • 64
  • 110
0
votes
0 answers

Difference between R base function `identical`l and `testthat` `expect_identical`?

Context xml_reserved_chars_to_named_entities <- function(string) { if(string == "" || identical(string, character(0))) return("") if(length(string) > 1) sapply(string, xml_reserved_chars_to_named_entities) chars <- unlist(strsplit(string,…
Ramiro Magno
  • 3,085
  • 15
  • 30
0
votes
1 answer

testthat .Rbuildignore + external file (NOTE)

Building a package using testthat for tests; those require an external file which as recommended lies in /tests/testthat/my-file. However the R CMD check produces Found the following hidden files and directories: tests/testthat/my-file The above…
JohnCoene
  • 2,107
  • 1
  • 14
  • 31
0
votes
1 answer

Run testthat tests on build and reload

Is there a way to run testthat tests on build and reload in RStudio? Is it possible to run only a subset of tests? I find myself writing a test, making a change, build+reload, then manually running tests.
Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255
0
votes
1 answer

Generic dispatching in a package after a call to devtools::test()

I am confused about something. when I put this function into a package oddTranspose <- function(x) { t(x) } it works fine m <- matrix(c(1,0,0,0), nrow=2) M <- as(m, "Matrix") oddTranspose(m) # works oddTranspose(M) # works but then, when I use…
pdb
  • 1,574
  • 12
  • 26
0
votes
0 answers

object no found error in testthat tests

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 =…
qed
  • 22,298
  • 21
  • 125
  • 196
0
votes
2 answers

Retrieving expected data.frame for testthat expectation

I'd like to test that a function returns the expected data.frame. The data.frame is too large to define in the R file (eg, using something like structure()). I'm doing something wrong with the environments when I try a simple retrieval from disk,…
wibeasley
  • 5,000
  • 3
  • 34
  • 62
0
votes
1 answer

test that function in r does not work

library(Rcpp) cppFunction(" int fib(int n) { if (n < 2) return(n); return( fib(n-1) + fib(n-2) ); } ") My task is to write several tests to show whether the case is wrong or not. However, the wrong messages…
0
votes
1 answer

Handling Test Workflows in R testthat

I've two files test_utils.r and test_core.r, they contain tests for various utilities and some core functions separated into different 'context'. I can control the flow of tests within each file by moving around my test_that() statements. But am…
BrajeshS
  • 1
  • 1
0
votes
0 answers

how to do automatic tests after a package build in R, Rstudio

how to do automatic tests after package build in R - Rstudio - testthat i have tried: testPath=paste(getwd(),"/tests/R/",sep="") codePath=paste(getwd(),"/R/",sep="") auto_test(test_path=testPath, code_path=codePath) but this react each time i…
phonixor
  • 1,623
  • 13
  • 18
0
votes
1 answer

Writing test_that tests that depend on other tests completing

I have written a series of test_that tests. There is one test_that test which has a side-effect of creating a sqlite3 table. The rest of the tests rely on this sqlite3 table. Is there a way to force this one test to run before any of the other…
andrew
  • 2,524
  • 2
  • 24
  • 36
0
votes
1 answer

How to test for folder existence using testthat in R

I have a function that will set up some folders for the rest of my workflow library(testthat) analysisFolderCreation<-function(projectTitle=NULL,Dated=FALSE,destPath=getwd(),SETWD=FALSE){ …
Steph Locke
  • 5,951
  • 4
  • 39
  • 77
0
votes
2 answers

How to make a test fail with the testthat package?

I have a test for which if the prerequisites are not met (e.g., missing file or something) I would like to make it fail. Just for clarification, here's an example I'd like to do: test_that("...", { if ( ... precondition to execute the test is…
rlegendi
  • 10,466
  • 3
  • 38
  • 50
-1
votes
1 answer

Missing import(Rcpp) in NAMESPACE leads to C++ library error during R CMD check of tests

Summary I am working on an R package that uses Rcpp. I took over the project with many issues and I am trying to fix them. The problem with this is that I don't know how to create a minimal example for reproduction in this situation because the…
williamjds
  • 13
  • 5
1 2 3
24
25