Home Wiki > openSUSE:Packaging R
Sign up | Login

openSUSE:Packaging R

tagline: From openSUSE


The Packaging R is a step by step introduction on how to build R software packages for openSUSE and others using the openSUSE Build Service.

About R

R is an open source programming language and software environment for statistical computing and graphics that is supported by the R Foundation for Statistical Computing. This language is heavily used in research as it provides a lot of statistical and graphical tools. It is also a well developed language for data manipulation.

Naming scheme

R packages’ names begin with a prefix “R-“, followed by the package name. For example, “R-waveslim”, with waveslim as the pacakage’s name.

Package repository sources

For official releases in openSUSE Build Service, the package doesn't need to be branched to your project directory. For unofficial or unstable releases, the package has to branched manually to your project directory and then built. To check whether your package has to be branched off, you can search it at https://software.opensuse.org/search.

Development repository & process

R language packages for openSUSE are developed at devel:languages:R repository in the openSUSE Build Service.

Packaging System

R language has a packaging system called CRAN (Comprehensive R Archive Network). CRAN is a network of ftp and web servers around the world that store identical, up-to-date, versions of code and documentation for R. R language packages are hosted on the site.

Specfile Example

%global packname foo
%global rlibdir  %{_libdir}/R/library

Name: R-%{packname}
Version: 0.0
Release: 0
Summary: Foo: Bar
Group: Development/Libraries/Other
License: GPL-2.0
URL: https://cran.r-project.org/src/contrib
Source0:  %{packname}_%{version}.tar.gz
BuildRoot:  %{_tmppath}/%{name}-%{version}-build
Requires: R-base
# Package suggestions, not required to build
#BuildRequires:
%description
FooBar.

%prep
%setup -q -c -n %{packname}

%build

%install
rm -rf %{buildroot}
mkdir -p %{buildroot}%{rlibdir}
%{_bindir}/R CMD INSTALL -l %{buildroot}%{rlibdir} %{packname}
test -d %{packname}/src && (cd %{packname}/src; rm -f *.o *.so)
rm -f %{buildroot}%{rlibdir}/R.css

%clean
rm -rf %{buildroot}

%check
%{_bindir}/R CMD check %{packname}

%files
%defattr(-, root, root, -)
%dir %{rlibdir}/%{packname}
%doc %{rlibdir}/%{packname}/DESCRIPTION
%doc %{rlibdir}/%{packname}/html
%{rlibdir}/%{packname}/INDEX
%{rlibdir}/%{packname}/NAMESPACE
%{rlibdir}/%{packname}/Meta
%{rlibdir}/%{packname}/R
%{rlibdir}/%{packname}/data
%{rlibdir}/%{packname}/help

%changelog

Dependencies

Some of the R packages depends on other packages besides R-base, it needs to be told on spec file. The dependencies can be found on package index at "https://cran.r-project.org/package={packagename}". In example, "https://cran.r-project.org/package=rex" is the description of package rex. The description in R packages has several ways of specifying dependencies :

  • Depends : Packages that the package heavily-dependent on.
  • Imports : Packages that required to complete the build.
  • Suggests: Packages that is optional to complete the build.

"R CMD check" requires all packages (depends, imports , suggests) to be present, otherwise it outputs an error. The package suggested can be ignored by "export _R_CHECK_FORCE_SUGGESTS=0" , but it's not recommended on packages that haven't been created on devel:languages:R repository in the openSUSE Build Service.

For suggested packages, even though you don't want to build with the package, it is always handy to still add it but as a comment, e.g.,

# Package suggestions, not required to build
# BuildRequires: R-Rserve, R-testthat

Running %build

%Build can be left empty.

Running %install

R CMD INSTALL can be used to install packages. It will install all files including documentation files.

Running %check

R CMD check can be used to check packages. R CMD check automatically checks your code for common problems. R CMD check is composed of over 50 individual checks, such as checking package directory, checking if this is a source package, etc. A complete list of checks can be found on http://r-pkgs.had.co.nz/check.html.

Testing R package

With testthat

Before you testing package with testthat,requires to add depend for testthat package

BuildRequires: R-testthat
BuildRequires:  texlive
BuildRequires:  texinfo
BuildRequires:  fdupes

After it,add script to test

%check
%{_bindir}/R CMD check %{packname}

Manual way

Execute Rscripts to test your package for test your package.If you have experience with R,you can write a script for test.If not,you can read manual in R package https://cran.r-project.org/doc/manuals/r-release/%{packname}.pdf and see the example for inspiration in write the script.And put the script on the %check</pre>,like on the front

%check
Rscript -e '(your script or dir of script)'

or

%check
R \
-e "(your script)"

Common problems on Building R package

Skipping Tests

Sometimes you need to force the rpm build despite the error(s) in a test, You can easily skip the test by using --no-tests flag on R CMD check.

Common problems on Files

You can get error from files. Error you got from files can be fixed by adding them to your %files.

First, read carefully the build logs.

If the build logs shows something like this

exit 0 Processing files: R-tint-0.0.3-19.1.i586 something that tells you that there is something in your package that haven't unpackaged yet

If you see that the files that is missing(unpackaged) is .Rd(usually NEWS.Rd) or anything that contain readable text(like LICENSE, CITATION, etc), use %doc before the directory of the file. else, you can add the directory without using %doc.

External links