0

I'm trying to implement testthat testing of someone else's R code (which was not packaged, when handed off to me).

When I Run Tests from RStudio, the following happens:

==> Testing R file using 'testthat'

i Loading public.supply.water.losses
i Re-compiling public.supply.water.losses (debug build)
-- R CMD INSTALL ---------------------------------------------------------------
* installing *source* package 'public.supply.water.losses' ...
** using staged installation
** libs
no DLL was created
ERROR: compilation failed for package 'public.supply.water.losses'
* removing 'C:/Users/ashalper/AppData/Local/Temp/1/RtmpEjDWo9/devtools_install_2ec07cae690a/public.supply.water.losses'
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, ...`:
! System command 'Rcmd.exe' failed
---
Exit status: 1
stdout & stderr: <printed>
---
Backtrace:
 1. devtools::load_all(dirname("~/src/public-supply-water-losses/tests/testt...
 2. pkgload::load_all(path = path, reset = reset, recompile = recompile, ...
 3. pkgbuild::compile_dll(path, quiet = quiet)
 4. pkgbuild:::install_min(path, dest = install_dir, components = "libs", args = if (ne...
 5. pkgbuild::rcmd_build_tools("INSTALL", c(path, paste("--library=", dest, ...
 6. pkgbuild::with_build_tools({ ...
 7. withr::with_path(rtools_path(), code)
 8. base::force(code)
 9. base::withCallingHandlers(callr::rcmd_safe(..., env = env, spinner = FALSE, ...
10. callr::rcmd_safe(..., env = env, spinner = FALSE, show = FALSE, ...
11. callr:::run_r(options)
12. base::with(options, with_envvar(env, do.call(processx::run, c(list(bin, ...
13. base::with.default(options, with_envvar(env, do.call(processx::run, ...
14. base::eval(substitute(expr), data, enclos = parent.frame())
15. base::eval(substitute(expr), data, enclos = parent.frame())
16. callr:::with_envvar(env, do.call(processx::run, c(list(bin, args = real_cmdargs,...
17. base::force(code)
18. base::do.call(processx::run, c(list(bin, args = real_cmdargs, stdout_line_call...
19. (function (command = NULL, args = character(), error_on_status = TRUE, ...
20. base::throw(new_process_error(res, call = sys.call(), echo = echo, ...
21. | base::signalCondition(cond)
22. (function (e) ...
23. asNamespace("callr")$err$throw(e)
Execution halted

Exited with status 1.

I'm not an every-day R programmer, so the backtrace (off in R library code?) is fairly inscrutable to me. Can anyone suggest a way to investigate this?

The same error occurs when I run devtools::check().

Thanks very much.

Andy Halper
  • 123
  • 3
  • 1
    It looks as if you are not getting past the "build" stage, not yet the testing stage. Is this package in a repo or only local? – r2evans Aug 17 '23 at 16:20
  • Only local (I think). This is the first R package I have attempted to build, and the motivation to have a package is entirely so I can use `testthat`. – Andy Halper Aug 17 '23 at 17:36
  • Ahh, I see the motivation. It's going to be difficult to separate "testthat" problems from "package build" problems if we don't know what else is going on. Like I said in the first comment, though, it feels as if the failure is before testing is attempted. Are you able to build and load the package sans tests? – r2evans Aug 17 '23 at 17:49
  • More info: I built the package successfully with: `library(devtools)` followed by `build()` but then it failed(with a very similar error) when I ran `install()`. – Andy Halper Aug 17 '23 at 18:20
  • 1
    I see, unfortunately it is likely to be failing for reasons we cannot see here. If your code is not proprietary and you have a repo on a public-facing code repository (e.g., GitHub, GitLab, BitBucket, not necessarily `git`-based), then I suggest you start a repo with your code and post the URL in your question. If you cannot (proprietary, or version-control is not in your capabilities), then I suggest you find a way to share a tarball of your current package (normal Stack mechanisms will not work, perhaps `paste.bin` or something similar, not my area of expertise). – r2evans Aug 17 '23 at 18:27
  • It's not proprietary, but the RCS is on a private network. Here is a ZIP archive of the branch I'm working on: https://drive.google.com/file/d/1IKeUs1CLr7QVibW7DchCjvqnGfaHrc-W/view?usp=sharing – Andy Halper Aug 19 '23 at 12:16
  • You must have an `./R/` directory. Having `.R` files in `src` does not work. If this is your package and/or you are not certain what you're doing, I find https://r-pkgs.org one of many good resources for building packages. **Bottom line**, at the top-level of your package directory, you should have `DESCRIPTION`, `NAMESPACE`, likely `LICENSE` (all of which you have), and at least directories `R` and `man`, optionally `tests`, `data`, `data-raw`, and `src`. Since nothing in `src` is for a compiled language (C, C++, or Fortran), then that directory does not belong. – r2evans Aug 19 '23 at 17:30
  • Another good resource is https://devtools.r-lib.org, where the *"aim of devtools is to make package development easier by providing R functions that simplify and expedite common tasks"*. Using it and perhaps walking through one of its example chapters [The Whole Game](https://r-pkgs.org/whole-game.html), I think it will start to make more sense (and start passing tests). – r2evans Aug 19 '23 at 17:42
  • As an alternative, it is possible to use `testthat` on scripts/functions that are not part of a formal package. See https://stackoverflow.com/a/45711967/3358272 and https://community.rstudio.com/t/testing-r-scripts-code-outside-of-package-development/10086. I don't do that (I maintain a few dozen packages), but I understand it can be a little clunky but otherwise can work. Good luck! – r2evans Aug 19 '23 at 17:43

0 Answers0