astamm / nloptr

nloptr provides an R interface to NLopt, a free/open-source library for nonlinear optimization providing a common interface to a number of different optimization routines which can handle nonlinear constraints and lower and upper bounds for the controls.

Home Page:https://astamm.github.io/nloptr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make tinytest unit test files self-sufficient

eddelbuettel opened this issue · comments

A nice side benefit of using tinytest is that a test file is "just a script" that can run by itself (possibly preceded by library(tinytest). Equally nice is that we can a file by itself: Rscript -e 'tinytest::run_test_file(filename)' (and ditto for run_test_dir().

I tend to do that "all the time" for my packages and have a small wrapper tt.r in littler which can flip between these modes. However, for nlopt this fails because we do not set the (optional but useful!) library(nloptr). Eg:

$ tt.r -f inst/tinytest/test-hs071.R        ## as is
test-hs071.R..................    0 tests    Error in nloptr(x0 = x0, eval_f = eval_f, lb = lb, ub = ub, eval_g_ineq = eval_g_ineq,  : 
  could not find function "nloptr"
$ 

After adding it:

$ tt.r -f inst/tinytest/test-hs071.R        ## after adding 'library(nloptr)``
test-hs071.R..................    5 tests OK 0.1s
All ok, 5 results (0.1s)
$ 

If there is consensus that this useful I can send a quick PR that adds the line to each file, I am already a couple files in.

No issues from me. Anything that makes this more robust is good.

Consensus it is. Thanks for bringing that up!

Now on its way!