Any way to user library packages loaded when entering packrat mode?

39 views
Skip to first unread message

Pete Thompson

unread,
Jan 3, 2018, 12:40:48 PM1/3/18
to packrat-discuss
I have a potentially unusual use case. I'd like to use Packrat when running R scripts under Spotfire Statistics Server. Spotfire is an enterprise platform that provides visualisation, analytics, data exploration, BI etc. functions and includes R integration. A Spotfire user can write R scripts and request that they execute on the Statistics Server, configuring data to be passed between Spotfire and the script (input and output R variables). 

Spotfire uses some custom packages to handle marshalling data between R and Spotfire, with the packages stored in a special library folder associated with the Statistics Server software. It then adds R wrapper code around the user provided script to call those packages and marshal the data, before executing R to run the script. We have several Statistics servers installed and the requests to run scripts can be load balanced to any of those servers, plus we setup new servers whenever we upgrade Spotfire (and occasionally to add capacity). I'd like to embed a Packrat based script in my 'user provided' script for a few reasons - mostly because I want to develop outside of Spotfire and then push the correct set of packages into a shared place that other users can make use of without having to deal with the complication of finding the right set of packages to copy to our servers, but also because I'd like to get the advantages of Packrat handling updates to packages appropriately as we add servers or upgrade the R version on the servers.. 

I can get a 'hacky' solution to work by writing a simple script that sources the '.rprofile' file in my Packrat project folder and forces initialisation. The problem is that Packrat unloads the Spotfire custom packages (quite understandable), plus removes the user library locations from the library path - thus I can't simply set the Spotfire packages to be external because Packrat can't find them in the system library. I've then hacked a little further so I capture the .libPaths prior to initialising Packrat, then place them back on the path and manually load the Spotfire packages, but I'm hoping there's a better way to do this! Ideally I'd be able to initialise Packrat and have it install the appropriate packages, but leave the existing libraries loaded. I'd particularly like to be able to do all this without hardcoding any Spotfire package names - I have no control over whether the vendor may choose to add packages (or remove them) in future, so one concern is that my scripts will break given the hardcoded names (I guess I could write something clever to find any packages that are loaded and reload them after Packrat does it's thing, but surely it would be easier to have an option for Packrat to leave things loaded?).

Pete Thompson

unread,
Jan 4, 2018, 5:51:34 AM1/4/18
to packrat-discuss
I think I have a slightly less 'hacky' solution. Instead of relying on Packrat to self-install/update, I'm going to rely on having a version available on my servers, then call the packrat::on function passing the clean.search.path parameter to avoid unloading the packages. I'm still not 100% happy given that this means I have to keep a version of Packrat somewhere available for the servers to load - it would be nice to be able to have Packrat auto-install and then load.

Kevin Ushey

unread,
Jan 4, 2018, 12:34:16 PM1/4/18
to Pete Thompson, packrat-discuss
Hi Pete,

Packrat uses project options to for project-level configuration. Perhaps we could introduce some more project options to accomplish what you're seeking to do here in a cleaner way?

You can see the set of existing options (after loading Packrat) with:

    ?"packrat-options"

If I understand correctly, you'd want two project options:

- 'external.libpaths': a set of library paths to append to the set of Packrat library paths
- 'clean.search.path': whether existing packages on the search path should be unloaded when activating this project

Does that sound right? You might also want to follow up at https://github.com/rstudio/packrat/issues, so we can track this for further development.

Thanks,
Kevin


--
You received this message because you are subscribed to the Google Groups "packrat-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packrat-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pete Thompson

unread,
Jan 5, 2018, 10:27:09 AM1/5/18
to packrat-discuss
Thanks Kevin! I've created an issue on github and posted some more thoughts.
To unsubscribe from this group and stop receiving emails from it, send an email to packrat-discu...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages