testthat

Automatic documentations of functions for Shiny app using RStudio

倾然丶 夕夏残阳落幕 提交于 2019-12-10 11:10:56
问题 I am developing a Shiny app at the moment and getting to a point with more functions than I expected. I plan to start automated testing with testthat and I would love to document my functions with roxygen2 . Since I am using RStudio, I started a new shiny app project. Now I am wondering, since I want the documentation and testing done, if I should instead start a package in RStudio to get all the devtools functions. I am wondering, how to get the functions documented properly and like in the

How to test for multiple warnings in an unknown order using testthat?

拜拜、爱过 提交于 2019-12-07 01:52:28
问题 I want to test that a function generates multiple warnings (4 or more), when the order of the warnings can vary. My best attempt to do this is based on look-ahead RegExp matching. Simplifying to just 2 warnings, I know my RegExp work on a single string output, because both of the following are true: grepl("(?s)(?=.*2)(?=.*1)", "* warn 1.\n* warn 2.", perl=TRUE) grepl("(?s)(?=.*2)(?=.*1)", "* warn 2.\n* warn 1.", perl=TRUE) However, this does not work when testing multiple warnings with

Unit tests for code in the /src folder of an R package?

柔情痞子 提交于 2019-12-05 22:45:50
问题 I am contributing to an R package that makes extensive use of C code for computation. We have started writing tests for R functions using the testthat package, placing the tests in inst/tests following instructions here. Is the testthat package appropriate for testing C functions directly (e.g. those without R interfaces)? Or do we find a separate C testing package? If so, 1) where should these tests go, 2) how do I get them to run during R CMD check , and 3) is any C testing package

Include tests in binary R package

☆樱花仙子☆ 提交于 2019-12-05 08:21:23
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. Ha! Got it. Found the information on the github page of testthat (it's at the very bottom). https://github.com

Test interaction with users in R package

一笑奈何 提交于 2019-12-05 02:28:18
问题 I am developing an R package and one of the function implements interaction with users through standard input via readline . I now wonder how to test the behavior of this function, preferably with testthat library. It seems test_that function assumes the answer is "" for user-input. I wish I could test the behavior conditional of various answers users may type in. Below is a small example code. In the actual development, the marryme function is defined in a separate file and exported to the

Unit tests for code in the /src folder of an R package?

自古美人都是妖i 提交于 2019-12-04 03:20:50
I am contributing to an R package that makes extensive use of C code for computation. We have started writing tests for R functions using the testthat package, placing the tests in inst/tests following instructions here . Is the testthat package appropriate for testing C functions directly (e.g. those without R interfaces)? Or do we find a separate C testing package? If so, 1) where should these tests go, 2) how do I get them to run during R CMD check , and 3) is any C testing package particularly appropriate in this context? I find the question a little confused: Either you consider your C

R testthat unit test data and helper function conventions

风格不统一 提交于 2019-12-03 23:33:41
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 weird to place functions that are only used for the unit tests in the R/ folder. It would be nice if could

How to setup testthat for R CMD check?

筅森魡賤 提交于 2019-12-03 01:29:10
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 will throw an error if there are any test failures. This means you'll see the full report of test

Unit test works as standalone but fails in test_that call

旧时模样 提交于 2019-12-02 15:21:58
问题 I’m running unit tests on the forecast package, specifically for the forecast.ar() function. I have a block of code that works just fine when run on its own. require(testthat) require(forecast) set.seed(55) simseries <- stats::arima.sim(model = list(ar = c(-0.42, 0.832, 0.1, -0.34)), n = 400) arfit <- stats::ar(simseries) fc1 <- forecast(arfit)$mean fc2 <- forecast(arfit, bootstrap = TRUE, npaths = 100, fan = TRUE)$mean expect_true(all(fc1 == fc2)) However, when I embed this in a test_that()

object no found error in testthat tests

左心房为你撑大大i 提交于 2019-12-02 08:28:05
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 = {}) { stopifnot(length(sym) == 1) e = new.env() e[[sym]] = x if(e[[sym]]) { eval(substitute(body1), e) } else {