3

How force R to load package when some (not crucial) packages it depends on aren't installed ?

Motivation : sometimes I have to use R in places, where I can't automatically install required packages. Doing so manually is very time consuming and in most cases I need only a vary small part of functions contained in installed package.

Typical message error in this case is :

> library(packageX)
Loading required package: packageY
Error: package ‘packageY’ could not be loaded
In addition: Warning messages:
In library(pkg, character.only = TRUE, logical.return = TRUE, lib.loc = lib.loc) : there is no package called ‘packageY’

Mayby 'devtools' package will be helpful. But I haven't investigate it.

smci
  • 32,567
  • 20
  • 113
  • 146
Qbik
  • 5,885
  • 14
  • 62
  • 93
  • It seems if you downloaded it and it depends on other packages then they should be in the library as well? – Tyler Rinker Aug 17 '12 at 23:05
  • If you can manually install individual packages, you should be able to automatically install packages too. The most common situation I have seen where people think they cannot auto install is when they are behind a corporate proxy. A fix for this which often works on Windows is to add --internet2 to the R invocation (e.g. edit your shortcut). This will ensure that R routes through the proxy set up for IE. – seancarmody Aug 17 '12 at 23:54

2 Answers2

2

If you cannot install the dependencies, I think your only option is to remove those packages from the Depends field of DESCRIPTION file of packageX and try to rebuild packageX

GSee
  • 48,880
  • 13
  • 125
  • 145
  • This is good idea. Is rebuilding needed or changing field in a DESCRIPTION file is sufficient (and why if you please)? – Qbik Aug 17 '12 at 23:18
  • You must rebuild/reinstall. `library` only loads installed packages. You need your installed packag to not not Depend on some package, so you have to change Depends, rebuild, reinstall. [Here is a post](http://stackoverflow.com/a/11105132/967840) to help show you how to build/install. – GSee Aug 17 '12 at 23:28
  • Note that changing the Depends is a bad idea. Packages usually depend on other packages for a reason. – GSee Aug 17 '12 at 23:28
1

You can look at the source of the package to figure out which functions you need and what dependencies they need. You may want to collaborate with the author/maintainer of the package on this part. You could create a private version of the package that does not have the dependencies and the other functionality that you don't need.

If this is only for your personal use and the license for the package allows it (gpl and similar) then you don't need the authors permission to extract those pieces you want. If you want to link your package to this for distribution then you should work with the original author. I know a couple of package authors wanted just a couple of functions from one of my packages and I agreed that loading my entire package (and dependencies) was overkill for what they wanted to do, so I worked with them and they have copies of the functions in their package without needing to depend on mine. When I update one of the functions I send a copy to them to update their copy as well.

Greg Snow
  • 48,497
  • 6
  • 83
  • 110