From Fedora Project Wiki

(Merge R Guideline changes)
m (Use modern contents formatting.)
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:Fedora Packaging Guidelines for R libraries}}
<div style="float: right; margin-left: 0.5em" class="toclimit-2">__TOC__</div>
== What is R? ==
== What is R? ==
The definition from [http://www.r-project.org/ The R-Project website]  says that R is:
The definition from [https://www.r-project.org/ The R-Project website]  says that R is:


''" R is a language and environment for statistical computing and graphics."''
''" R is a language and environment for statistical computing and graphics."''
Line 10: Line 13:


If you are looking for more information on R, you can go to:
If you are looking for more information on R, you can go to:
* [http://www.r-project.org/ The R-Project website]  
* [https://www.r-project.org/ The R-Project website]  
* [http://cran.r-project.org/doc/manuals/R-intro.html An introduction to R]  
* [https://cran.r-project.org/doc/manuals/R-intro.html An introduction to R]  


If you are interested in packaging R modules, or if you are looking for R libraries, you should check here for upstream sources:
If you are interested in packaging R modules, or if you are looking for R libraries, you should check here for upstream sources:
* [http://www.bioconductor.org/ The bioconductor website]  
* [https://www.bioconductor.org/ The bioconductor website]  
* [http://cran.r-project.org/ The CRAN website]  
* [https://cran.r-project.org/ The CRAN website]  
* [http://r-forge.r-project.org/ The R-forge from the R-Project website]
* [https://r-forge.r-project.org/ The R-forge from the R-Project website]
* [http://www.rforge.net/ The RForge website]
* [https://www.rforge.net/ The RForge website]


== Spec Templates for R packages ==
== Spec Templates for R packages ==
Line 33: Line 36:
Release:          1%{?dist}
Release:          1%{?dist}
Source0:          ftp://cran.r-project.org/pub/R/contrib/main/%{packname}_%{version}-%{packrel}.tar.gz
Source0:          ftp://cran.r-project.org/pub/R/contrib/main/%{packname}_%{version}-%{packrel}.tar.gz
License:          GPL
License:          GPLv2+
URL:              http://cran.r-project.org/src/contrib
URL:              https://cran.r-project.org/src/contrib
Group:            Applications/Engineering
Summary:          Adds foo functionality for R
Summary:          Adds foo functionality for R
BuildRequires:    R-devel, tex(latex)
BuildRequires:    R-devel, tex(latex)
BuildRoot:        %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Requires(post):  R
Requires(postun): R


%description
%description
Line 51: Line 50:


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


%check
%check
%{_bindir}/R CMD check %{packname}
%{_bindir}/R CMD check %{packname}
%clean
rm -rf $RPM_BUILD_ROOT
%post
%{_R_make_search_index}
%postun
%{_R_make_search_index}


%files
%files
%defattr(-, root, root, -)
%dir %{_libdir}/R/library/%{packname}
%dir %{_libdir}/R/library/%{packname}
%doc %{_libdir}/R/library/%{packname}/latex
%doc %{_libdir}/R/library/%{packname}/doc
%doc %{_libdir}/R/library/%{packname}/doc
%doc %{_libdir}/R/library/%{packname}/html
%doc %{_libdir}/R/library/%{packname}/html
%doc %{_libdir}/R/library/%{packname}/man
%doc %{_libdir}/R/library/%{packname}/DESCRIPTION
%doc %{_libdir}/R/library/%{packname}/NEWS
%doc %{_libdir}/R/library/%{packname}/NEWS
%{_libdir}/R/library/%{packname}/CONTENTS
%{_libdir}/R/library/%{packname}/DESCRIPTION
%{_libdir}/R/library/%{packname}/INDEX
%{_libdir}/R/library/%{packname}/INDEX
%{_libdir}/R/library/%{packname}/NAMESPACE
%{_libdir}/R/library/%{packname}/NAMESPACE
Line 87: Line 72:


%changelog
%changelog
* Fri Jul 6 2007 Tom "spot" Callaway <tcallawa@redhat.com> 1.6.6-1
* Fri Jul 6 2007 Tom "spot" Callaway <tcallawa@redhat.com> - 1.6.6-1
- Initial package creation
- Initial package creation
</pre>
</pre>
Line 101: Line 86:
Release:          1%{?dist}
Release:          1%{?dist}
Source0:          ftp://cran.r-project.org/pub/R/contrib/main/%{packname}_%{version}-%{packrel}.tar.gz
Source0:          ftp://cran.r-project.org/pub/R/contrib/main/%{packname}_%{version}-%{packrel}.tar.gz
License:          GPL
License:          GPLv2+
URL:              http://cran.r-project.org/src/contrib
URL:              https://cran.r-project.org/src/contrib
Group:            Applications/Engineering
Summary:          Adds foo functionality for R
Summary:          Adds foo functionality for R
BuildRequires:    R-devel, tex(latex)
BuildRequires:    R-devel, tex(latex)
BuildRoot:        %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildArch:        noarch
BuildArch:        noarch
Requires(post):  R
Requires:        R-core
Requires(postun): R
Requires:        R


%description
%description
Line 121: Line 102:


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


%check
%check
%{_bindir}/R CMD check %{packname}
%{_bindir}/R CMD check %{packname}
%clean
rm -rf $RPM_BUILD_ROOT
%post
%{_R_make_search_index}
%postun
%{_R_make_search_index}


%files
%files
%defattr(-, root, root, -)
%dir %{_datadir}/R/library/%{packname}
%dir %{_datadir}/R/library/%{packname}
%doc %{_datadir}/R/library/%{packname}/latex
%doc %{_datadir}/R/library/%{packname}/doc
%doc %{_datadir}/R/library/%{packname}/doc
%doc %{_datadir}/R/library/%{packname}/html
%doc %{_datadir}/R/library/%{packname}/html
%doc %{_datadir}/R/library/%{packname}/man
%doc %{_datadir}/R/library/%{packname}/DESCRIPTION
%doc %{_datadir}/R/library/%{packname}/NEWS
%doc %{_datadir}/R/library/%{packname}/NEWS
%{_datadir}/R/library/%{packname}/CONTENTS
%{_datadir}/R/library/%{packname}/DESCRIPTION
%{_datadir}/R/library/%{packname}/INDEX
%{_datadir}/R/library/%{packname}/INDEX
%{_datadir}/R/library/%{packname}/NAMESPACE
%{_datadir}/R/library/%{packname}/NAMESPACE
Line 157: Line 124:


%changelog
%changelog
* Fri Jul 6 2007 Tom "spot" Callaway <tcallawa@redhat.com> 1.6.6-1
* Fri Jul 6 2007 Tom "spot" Callaway <tcallawa@redhat.com> - 1.6.6-1
- Initial package creation
- Initial package creation
</pre>
</pre>
Line 163: Line 130:
=== Summary of differences between arch-specific and noarch R packages ===
=== Summary of differences between arch-specific and noarch R packages ===


* Noarch packages set <code>BuildArch: noarch</code>
* Noarch packages set <code>BuildArch: noarch</code>.
* Noarch packages install into <code>%{_datadir}/R/library/%{packname}</code>, arch-specific packages install into <code>%{_libdir}/R/library/%{packname}</code>
* Noarch packages install into <code>%{_datadir}/R/library/%{packname}</code>; arch-specific packages install into <code>%{_libdir}/R/library/%{packname}</code>.
* Noarch packages have <code>Requires: R-core</code>.  For arch-specific packages, RPM will automatically add an appropriate dependency on the needed shared libraries but noarch packages need this added manually.


=== R2spec ===
=== R2spec ===
R2spec is an excellent little tool to assist in creating Fedora-compliant packages for R libraries. Using it as a starting point is recommended (but certainly not mandated).
R2spec is an excellent little tool to assist in creating Fedora-compliant packages for R libraries. Using it as a starting point is recommended (but certainly not mandated).
More information here : https://fedorahosted.org/r2spec/
More information here : https://pagure.io/r2spec/


== R packaging tips ==
== R packaging tips ==
Line 194: Line 162:


=== Empty %build section ===
=== Empty %build section ===
Unlike normal Fedora packages, there is normally no separate <code>%build</code> actions (e.g. <code>%configure</code>)that need to be taken for an R package. However, it is important that all R module packages include an empty %build section, as shown in the spec templates.
Unlike normal Fedora packages, there is normally no separate <code>%build</code> actions (e.g. <code>%configure</code>)that need to be taken for an R package. However, it is important that all R module packages include an empty <code>%build</code> section, as shown in the spec templates.


=== Installing the R addon bits ===
=== Installing the R addon bits ===
Instead of calling make install, to install the R addon components, you need to run <code>R CMD INSTALL -l $RPM_BUILD_ROOT%{_datadir}/R/library %{packname}</code> (noarch) or <code>R CMD INSTALL -l $RPM_BUILD_ROOT%{_libdir}/R/library %{packname}</code> (arch-specific). Proper <code>%install</code> sections for Fedora R packages are demonstrated in the spec templates.
Instead of calling make install, to install the R addon components, you need to run <code>R CMD INSTALL -l %{buildroot}%{_datadir}/R/library %{packname}</code> (noarch) or <code>R CMD INSTALL -l %{buildroot}%{_libdir}/R/library %{packname}</code> (arch-specific). Proper <code>%install</code> sections for Fedora R packages are demonstrated in the spec templates.


=== Deleting the R.css file ===
=== Deleting the R.css file ===
Most R addon modules generate a new R.css file, but it would conflict with the master R.css file, included in the main R package. You must delete this file, and do not include it in your package.
Most R addon modules generate a new <code>R.css file</code>, but it would conflict with the master <code>R.css</code> file, included in the main R package. You must delete this file, and do not include it in your package.
 
=== Generating the search index.txt ===
R keeps a master index.txt, as a search index of which R libraries are installed on the system. This provides the source for the R html help interface that is accessible through the ''help.start()'' command. This index is always located at <code>/usr/share/doc/R-%{version}/html/search/index.txt</code>. All R packages need to update the search index.txt in %post and %postun. The R package provides a macro to make this simple: <code>%{_R_make_search_index}</code>. Simply put this macro in %post and %postun in your R package, and it will update the search index.txt to include arch-specific and noarch R libraries upon install and uninstall. This is demonstrated in the spec templates.
 
NOTE: R packages will throw the following warning from rpmlint:
<pre>
W: R-widgetTools one-line-command-in-%post
/usr/lib/rpm/R-make-search-index.sh
</pre>
 
Normally, this would be resolved by running <code>%post -p foo</code>, but this will not work with our script.
Just ignore this warning.


=== Cleaning the R directory of binaries ===
=== Cleaning the R directory of binaries ===
It is important to clean the R directory of binary files (*.o *.so) before running R CMD CHECK. Otherwise, the CHECK command will throw a warning about finding binaries in the source dir. This is accomplished by running (in %install):
It is important to clean the R directory of binary files (<code>*.o *.so</code>) before running <code>R CMD CHECK</code>. Otherwise, the CHECK command will throw a warning about finding binaries in the source dir. This is accomplished by running (in <code>%install</code>):


<pre>
<pre>
Line 234: Line 190:


=== Documentation files ===
=== Documentation files ===
The <code>R CMD INSTALL</code> operation will install all of the files, including documentation files. The latex, doc, html, man, NEWS, and DESCRIPTION files/directories need to be marked as <code>%doc</code>.
The <code>R CMD INSTALL</code> operation will install all of the files, including documentation files. The doc, html and NEWS files/directories need to be marked as <code>%doc</code>.
Note that other files, such as CONTENTS, INDEX, NAMESPACE, and help/ are not <code>%doc</code>, since proper R functionality depends on their presence. Be careful not to duplicate <code>%doc</code> files in the package, the spec templates provide good examples on how to package the R addon files without duplications.
Note that other files, such as DESCRIPTION, INDEX, NAMESPACE, and help/ are not <code>%doc</code>, since proper R functionality depends on their presence. Be careful not to duplicate <code>%doc</code> files in the package, the spec templates provide good examples on how to package the R addon files without duplications.


==== R documentation ====
==== R documentation ====
R documentation is written in Tex. rpmlint sometimes complains that these Tex files are not utf-8 files, but the encoding is normally specified in the file when needed, so this error is safe to ignore (and you should not try to re-encode the files).
R documentation is written in TeX. rpmlint sometimes complains that these TeX files are not utf-8 files, but the encoding is normally specified in the file when needed, so this error is safe to ignore (and you should not try to re-encode the files).


=== Optimization flags ===
=== Optimization flags ===
R packages inherit their optimization flags from the main R package, which stores them in <code>%{_libdir}/R/etc/Makeconf</code>. The design of R is such that all R addon library modules use the same optimization flags that the main R package was built with. Accordingly, this is why R addon packages do not pass <code>$RPM_OPT_FLAGS</code>. Also, there is no simple way to pass special optimization flags to <code>R CMD INSTALL</code>.
R packages inherit their optimization flags from the main R package, which stores them in <code>%{_libdir}/R/etc/Makeconf</code>. The design of R is such that all R addon library modules use the same optimization flags that the main R package was built with. Accordingly, this is why R addon packages do not pass <code>%{optflags}</code>. Also, there is no simple way to pass special optimization flags to <code>R CMD INSTALL</code>.


=== R headers ===
=== R headers ===
R packages usually expect to find their header files in %{_libdir}/R/library/*/. rpmlint will complain that these files are misplaced, but this is safe to ignore.
R packages usually expect to find their header files in <code>%{_libdir}/R/library/*/</code>. rpmlint will complain that these files are misplaced, but this is safe to ignore.


You should still separate these header files into a -devel subpackage.
You should still separate these header files into a -devel subpackage.
[[Category:Packaging guidelines]]

Revision as of 18:04, 19 April 2018

What is R?

The definition from The R-Project website says that R is:

" R is a language and environment for statistical computing and graphics."

R is a GNU project, very similar to the S language developed by Bell Laboratories.

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.

If you are looking for more information on R, you can go to:

If you are interested in packaging R modules, or if you are looking for R libraries, you should check here for upstream sources:

Spec Templates for R packages

There are two types of R packages: arch-specific and noarch.

Arch specific R packaging spec template

%global packname foo
%global packrel 1

Name:             R-%{packname}
Version:          1.6.6
Release:          1%{?dist}
Source0:          ftp://cran.r-project.org/pub/R/contrib/main/%{packname}_%{version}-%{packrel}.tar.gz
License:          GPLv2+
URL:              https://cran.r-project.org/src/contrib
Summary:          Adds foo functionality for R
BuildRequires:    R-devel, tex(latex)

%description
R Interface to foo, enables bar!

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

%build

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

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

%files
%dir %{_libdir}/R/library/%{packname}
%doc %{_libdir}/R/library/%{packname}/doc
%doc %{_libdir}/R/library/%{packname}/html
%doc %{_libdir}/R/library/%{packname}/NEWS
%{_libdir}/R/library/%{packname}/DESCRIPTION
%{_libdir}/R/library/%{packname}/INDEX
%{_libdir}/R/library/%{packname}/NAMESPACE
%{_libdir}/R/library/%{packname}/Meta
%{_libdir}/R/library/%{packname}/R
%{_libdir}/R/library/%{packname}/R-ex
%{_libdir}/R/library/%{packname}/help

%changelog
* Fri Jul 6 2007 Tom "spot" Callaway <tcallawa@redhat.com> - 1.6.6-1
- Initial package creation

Noarch R packaging spec template

%global packname foo
%global packrel 1

Name:             R-%{packname}
Version:          1.6.6
Release:          1%{?dist}
Source0:          ftp://cran.r-project.org/pub/R/contrib/main/%{packname}_%{version}-%{packrel}.tar.gz
License:          GPLv2+
URL:              https://cran.r-project.org/src/contrib
Summary:          Adds foo functionality for R
BuildRequires:    R-devel, tex(latex)
BuildArch:        noarch
Requires:         R-core

%description
R Interface to foo, enables bar!

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

%build

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

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

%files
%dir %{_datadir}/R/library/%{packname}
%doc %{_datadir}/R/library/%{packname}/doc
%doc %{_datadir}/R/library/%{packname}/html
%doc %{_datadir}/R/library/%{packname}/NEWS
%{_datadir}/R/library/%{packname}/DESCRIPTION
%{_datadir}/R/library/%{packname}/INDEX
%{_datadir}/R/library/%{packname}/NAMESPACE
%{_datadir}/R/library/%{packname}/Meta
%{_datadir}/R/library/%{packname}/R
%{_datadir}/R/library/%{packname}/R-ex
%{_datadir}/R/library/%{packname}/help

%changelog
* Fri Jul 6 2007 Tom "spot" Callaway <tcallawa@redhat.com> - 1.6.6-1
- Initial package creation

Summary of differences between arch-specific and noarch R packages

  • Noarch packages set BuildArch: noarch.
  • Noarch packages install into %{_datadir}/R/library/%{packname}; arch-specific packages install into %{_libdir}/R/library/%{packname}.
  • Noarch packages have Requires: R-core. For arch-specific packages, RPM will automatically add an appropriate dependency on the needed shared libraries but noarch packages need this added manually.

R2spec

R2spec is an excellent little tool to assist in creating Fedora-compliant packages for R libraries. Using it as a starting point is recommended (but certainly not mandated). More information here : https://pagure.io/r2spec/

R packaging tips

Naming of R packages

Packages of R modules (thus they rely on R as a parent) have their own naming scheme. They should take into account the upstream name of the R module. This makes a package name format of R-$NAME. When in doubt, use the name of the module that you type to import it in R.

Examples:

R-mAr (R module named mAr)
R-RScaLAPACK (R module named RScaLAPACK)
R-waveslim (R module named waveslim)

R version

Many R packages contain '-' in their version. Usually, the versioning used is a sequence of at least two (and usually three) non-negative integers separated by single '.' or '-' characters.

To be consistent with the versioning system used in Fedora, you should simply replace dashes with dots.

Example:

Upstream tarball: Rfoo-0.5-8.tar.gz
Fedora Version: 0.5.8

Empty %build section

Unlike normal Fedora packages, there is normally no separate %build actions (e.g. %configure)that need to be taken for an R package. However, it is important that all R module packages include an empty %build section, as shown in the spec templates.

Installing the R addon bits

Instead of calling make install, to install the R addon components, you need to run R CMD INSTALL -l %{buildroot}%{_datadir}/R/library %{packname} (noarch) or R CMD INSTALL -l %{buildroot}%{_libdir}/R/library %{packname} (arch-specific). Proper %install sections for Fedora R packages are demonstrated in the spec templates.

Deleting the R.css file

Most R addon modules generate a new R.css file, but it would conflict with the master R.css file, included in the main R package. You must delete this file, and do not include it in your package.

Cleaning the R directory of binaries

It is important to clean the R directory of binary files (*.o *.so) before running R CMD CHECK. Otherwise, the CHECK command will throw a warning about finding binaries in the source dir. This is accomplished by running (in %install):

test -d %{packname}/src && (cd %{packname}/src; rm -f *.o *.so)

This is demonstrated in the spec templates.

Running %check

Most (if not all) R addon modules come with a built-in check. This can be triggered by running R CMD check. In Fedora, the check should be run in the %check section. Here is an example %check section for a Fedora R package:

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

Note that frequently, R packages have circular dependency loops when running R CMD check. If you hit such a case, you can comment out the check to break the dependency loop, and leave a comment explaining the circular dependency problem.

Documentation files

The R CMD INSTALL operation will install all of the files, including documentation files. The doc, html and NEWS files/directories need to be marked as %doc. Note that other files, such as DESCRIPTION, INDEX, NAMESPACE, and help/ are not %doc, since proper R functionality depends on their presence. Be careful not to duplicate %doc files in the package, the spec templates provide good examples on how to package the R addon files without duplications.

R documentation

R documentation is written in TeX. rpmlint sometimes complains that these TeX files are not utf-8 files, but the encoding is normally specified in the file when needed, so this error is safe to ignore (and you should not try to re-encode the files).

Optimization flags

R packages inherit their optimization flags from the main R package, which stores them in %{_libdir}/R/etc/Makeconf. The design of R is such that all R addon library modules use the same optimization flags that the main R package was built with. Accordingly, this is why R addon packages do not pass %{optflags}. Also, there is no simple way to pass special optimization flags to R CMD INSTALL.

R headers

R packages usually expect to find their header files in %{_libdir}/R/library/*/. rpmlint will complain that these files are misplaced, but this is safe to ignore.

You should still separate these header files into a -devel subpackage.