How to include more paths under INCLUDE_DIR in configure.vars argument in install.packages() function in R?
Asked Answered
C

2

6

I have a problem with gdtools package. I would like to install it from source, but unfortunately I am not able to install any extra libs on Linux box. What I am doing to solve it, it is inclusion of packages in time of installation:

install.packages(repos = c("http://localhost.net/cran"), type = "source", pkgs = c('gdtools'), configure.vars = c("INCLUDE_DIR=/extra/gdtools/windows/cairo-1.15.10/include/cairo"))

This allows me to go one step further. But then I need to include one more directory, pointing to freetype library: /extra/gdtools/windows/cairo-1.15.10/include/freetype2/freetype

But when I am trying to add it to command it is not working. I have tried to do it in many ways, for example like that it is not working:

install.packages(repos = c("http://localhost.net/cran"), type = "source", pkgs = c('gdtools'), configure.vars = c("INCLUDE_DIR=/extra/gdtools/windows/cairo-1.15.10/include/cairo /extra/gdtools/windows/cairo-1.15.10/include/freetype2/freetype"))

Can somebody help me how to do it? I have tried also from R CMD level. Any solution is acceptable for me.

Cinder answered 15/11, 2018 at 17:25 Comment(0)
U
9

This can be a pretty confusing situation since the R documentation does not explicitly tell you how to do this. However, there are a couple of options that should get the job done. As you will see in the examples, the trick is how to put the strings together. To get more than one directory in INCLUDE_DIR or LIB_DIR, simply embed the multiple directories in single quotes within the full double-quoted string. Notice, though, that you do not need to place the -I or -L flags at the start of the string but you do have to place them ahead of the additional directories. This is because R will prepend it for you after parsing out the INCLUDE_DIR and LIB_DIR.

A caveat to these methods is that each package is free to implement other variables and methods of looking for libraries and headers. While LIB_DIR and INCLUDE_DIR seem to be commonly used, it is possible to find a package that uses other specific environmental variables in place of those. It is also possible that a package does not prepend -I or -L. Just be cognizant of what the package expects. The good news is that these general principles should still apply even with changes in variable names, etc.

Using configure vars

Configure vars is available in command line installation

R CMD INSTALL --configure-vars="LIB_DIR='/my/lib/dir1 -L/my/lib/dir2' INCLUDE_DIR='/my/include/dir1 /my/include/dir2'" /path/to/myPackage

or within R

install.packages("myPackage", configure.vars=c("LIB_DIR='/my/lib/dir1 -L/my/lib/dir2' INCLUDE_DIR='/my/include/dir1 -I/my/include/dir2'"))

Using .Renviron

You can also set environment variables for R in the .Renviron file. This file is read by R on startup. See the R documentation on how R handles .Renviron and where it expects it to be located. You can simply add the variables you want in the file and R will use them when installing packages.

LIB_DIR="/my/lib/dir1 -L/my/lib/dir2"
INCLUDE_DIR="/my/include/dir2 -I/my/include/dir2"

While this option can be convenient, it also means these variables will be used for all packages. The configure vars method is perhaps better for one-off installs or when you need per-package settings (which is done via named vectors or lists).

Unanimous answered 13/1, 2021 at 22:2 Comment(0)
A
0

Using the configure.vars option did not work for me. I've not tried using .Renviron.

The R project doc section on Customizing package compilation explains how to use a $HOME/.R/Makevars file to do this. Populating with: PKG_CPPFLAGS_SITE = -I/path/to/my/custom/usr/local/include where my headers are worked.

If it is a one-off need, I think that an environment variable export PKG_CPPFLAGS_SITE=-I/path/to/my/usr/local/include before launching R also works.

Antonetteantoni answered 4/4, 2023 at 6:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.