rshinyr-package

R Shiny Packaging: ERROR: unable to collate and parse R files for package ‘xx’


I am writing a Shiny app and have packaged the entire app into a package. Let's call this app/package fruit

Every time I made changes to the app, I would do the following:

library(devtools)
install()
library(fruit)
run_fruit_app()

I suspect that I messed up something while editing, now after I run install(), the following error messages pops up:

Running /Library/Frameworks/R.framework/Resources/bin/R CMD INSTALL \
  /var/folders/t6/v39yjp39xxxxxx/T//Rtmpxxx/fruit_0.1.0.tar.gz --install-tests 
* installing to library ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library’
* installing *source* package ‘fruit’ ...
** using staged installation
** R
Error in parse(outFile) : 
  /private/var/folders/t6/v39yjp39xxxxxx/T/Rtmpxxx/R.INSTALL11a89xxx/fruit/R/testing.R:1:1: unexpected symbol
1: library
    ^
ERROR: unable to collate and parse R files for package ‘fruit’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/fruit’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/fruit’
Error in (function (command = NULL, args = character(), error_on_status = TRUE,  : 
  System command 'R' failed, exit status: 1, stdout & stderr were printed
> .Last.error.trace 

 Stack trace:

 1. devtools:::install()
 2. pkgbuild::with_build_tools(required = FALSE, callr::rcmd("INSTALL",  ...
 3. callr::rcmd("INSTALL", c(install_path, opts), echo = !quiet,  ...
 4. callr:::run_r(options)
 5. base:::with(options, with_envvar(env, do.call(processx::run,  ...
 6. base:::with.default(options, with_envvar(env, do.call(processx::run,  ...
 7. base:::eval(substitute(expr), data, enclos = parent.frame())
 8. base:::eval(substitute(expr), data, enclos = parent.frame())
 9. callr:::with_envvar(env, do.call(processx::run, c(list(bin, args = real_cmdargs,  ...
 10. base:::force(code)
 11. base:::do.call(processx::run, c(list(bin, args = real_cmdargs,  ...
 12. (function (command = NULL, args = character(), error_on_status = TRUE,  ...
 13. throw(new_process_error(res, call = sys.call(), echo = echo,  ...

 x System command 'R' failed, exit status: 1, stdout & stderr were printed 

What could be potential source of errors? I did make sure that I did not forget to close a bracket, used a wrong bracket, or set things in the wrong working directory.

Any insights are much appreciated!


Solution

  • As mentioned in the comments, I recommend you do :

    library(devtools)
    check()
    load_all()
    run_fruit_app()
    

    instead of installing the package every time you need to check something. Also, check() will tell you if there are problems with your code. I guess you have a call to library() somewhere in your code.

    Finally, I also have a shiny app that is packaged. Just in case you need to check something, this is the link to the repo https://github.com/tomicapretto/sdeshiny

    Good luck!