20

I am trying to install some R packages on a Linux machine using

R CMD INSTALL -l <ourRlibrarylocation> <path where I saved the packagename.tar.gz file>

and I see an error message:

ERROR: a 'NAMESPACE' file is required

I am using R 3.0.1. Please help, I am new to R and just downloaded these packages for customers.

One example:

 R CMD INSTALL -l /abcde/R/R-3.0.0/library /home/RFILES/PKG/UScensus2000tract_0.03.tar.gz
* installing *source* package âUScensus2000tractâ ...
ERROR: a 'NAMESPACE' file is required
* removing â/abcde/R/R-3.0.0/library/UScensus2000tractâ
zx8754
  • 52,746
  • 12
  • 114
  • 209
user2448881
  • 311
  • 1
  • 3
  • 7

4 Answers4

42

According to the R documentation for writing extensions, all packages destined for version 3.0.0 and later must contain a NAMESPACE file. If you download an R package that gives you the above error, here's what you should try:

Untar the package:

tar -xvf the_package.tar.gz

Add a NAMESPACE file with the line exportPattern( "." ):

cd the_package
echo 'exportPattern( "." )' > NAMESPACE
cd ..

Re-tar the package:

tar -zcf the_package.tar.gz the_package

Try and install it again.

Hope that helps.

polarise
  • 2,303
  • 1
  • 19
  • 28
  • 1
    Great solution! On Windows, you can use `echo exportPattern( "." ) > NAMESPACE` instead of `echo 'exportPattern( "." )' > NAMESPACE`. – imriss Apr 22 '15 at 20:00
4

I actually just hit the same thing when compiling R-3.0.1. It looks to be that the package version that I was using was out of date. This was for proto:

# /var/local/R-3.0.1/bin/R CMD INSTALL -l /var/local/R-3.0.1/lib64/R/library proto_0.3-9.2.tar.gz
* installing *source* package ‘proto’ ...
ERROR: a 'NAMESPACE' file is required
* removing ‘/var/local/R-3.0.1/lib64/R/library/proto’

But there was a newer version for proto (0.3-10) which worked fine:

# ../var/local/R-3.0.1/bin/R CMD INSTALL -l ../var/local/R-3.0.1/lib64/R/library proto_0.3-10.tar.gz
* installing *source* package ‘proto’ ...
** package ‘proto’ successfully unpacked and MD5 sums checked
** R
** demo
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
   ‘proto.Rnw’
   ‘protoref.Rnw’
** testing if installed package can be loaded
* DONE (proto)

I had an older install of R (2.15), which the older proto package worked with:

# /var/local/R-2.15.0/bin/R CMD INSTALL -l /var/local/R-2.15.0/lib64/R/library proto_0.3-9.2.tar.gz
* installing *source* package 'proto' ...
** Creating default NAMESPACE file
** R
** demo
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
   'proto.Rnw'
   'protoref.Rnw'
** testing if installed package can be loaded

It looks like the older version of R actually creates the missing NAMESPACE file, but the new version bails. Hope this helps you!

Christopher Neylan
  • 8,018
  • 3
  • 38
  • 51
3

I found the following link more useful: How should I deal with "package 'xxx' is not available (for R version x.y.z)" warning?

6. The package is out of date

It may have been archived (if it is no longer maintained and no longer passes R CMD check tests).

In this case, you can load an old version of the package using install_version()

library(devtools)
install_version("foobarbaz", "0.1.2")

An alternative is to install from the github CRAN mirror.

library(devtools)
install_github("cran/foobarbaz")
SilverNak
  • 3,283
  • 4
  • 28
  • 44
Peter
  • 31
  • 1
  • For package `GeneTS`, `install_github` throws an error of `ERROR: a 'NAMESPACE' file is required `. Is it expected? – bapors Apr 03 '18 at 12:36
1

One can now use remotes::install_url() or remotes::install_local().

It installs dependencies and generates the NAMESPACE file automatically.

F. Privé
  • 11,423
  • 2
  • 27
  • 78