Wysokiej jakości grafiki (antyaliasing) w pakiecie R

Aby móc renderować grafiki wysokiej jakości (np. z aktywnym antyaliasingiem) należy zainstalować bibliotekę Cairo (polecenie wykonujemy w konsoli R):

install.packages(c("Cairo"), repos="http://cran.r-project.org")

System rozpocznie pobieranie i kompilowanie biblioteki. Jeżeli podczas instalacji otrzymamy komunikat o braku pliku cairo.h:

Warning in install.packages(c("Cairo"), repos = "http://cran.r-project.org") :
argument 'lib' is missing: using '/usr/local/lib/R/site-library'
trying URL 'http://cran.r-project.org/src/contrib/Cairo_1.5-1.tar.gz'
Content type 'application/x-gzip' length 81918 bytes (79 Kb)
opened URL
==================================================
downloaded 79 Kb

* installing *source* package 'Cairo' ...
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no

...

checking if R was compiled with the RConn patch... no
checking cairo.h usability... no
checking cairo.h presence... no
checking for cairo.h... no
configure: error: Cannot find cairo.h! Please install cairo (http://www.cairographics.org/) and/or set CAIRO_CFLAGS/LIBS correspondingly.
ERROR: configuration failed for package 'Cairo'
* removing '/usr/local/lib/R/site-library/Cairo'
* restoring previous '/usr/local/lib/R/site-library/Cairo'

The downloaded packages are in
'/tmp/RtmpevzXi8/downloaded_packages'
Warning message:
In install.packages(c("Cairo"), repos = "http://cran.r-project.org") :
installation of package 'Cairo' had non-zero exit status

to znaczy, że nie mamy w systemie paczki z plikami źródłowymi biblioteki Cairo. Instalujemy pakiet „libcairo2-dev”:

apt-get install libcairo2-dev

Ponownie próbujemy pobrać bibliotekę Cairo:

install.packages(c("Cairo"), repos="http://cran.r-project.org")

Możemy otrzymać kolejny komunikat o braku plików z nagłówkami:

xlib-backend.c:34:74: error: X11/Intrinsic.h: No such file or directory
xlib-backend.c: In function 'Rcairo_init_xlib':
xlib-backend.c:158: warning: implicit declaration of function 'XrmUniqueQuark'
make: *** [xlib-backend.o] Error 1
ERROR: compilation failed for package 'Cairo'
* removing '/usr/local/lib/R/site-library/Cairo'

Instalujemy kolejną paczkę:

apt-get install libxt-dev

Jeszcze raz uruchamiamy konsolę R i próbujemy zainstalować Cairo. Jeżeli instalacja przebiegnie pomyślnie, to na końcu otrzymamy następujący komunikat:

Warning in install.packages(c("Cairo"), repos = "http://cran.r-project.org") :
argument 'lib' is missing: using '/usr/local/lib/R/site-library'
trying URL 'http://cran.r-project.org/src/contrib/Cairo_1.5-1.tar.gz'
Content type 'application/x-gzip' length 81918 bytes (79 Kb)
opened URL
==================================================
downloaded 79 Kb

* installing *source* package 'Cairo' ...
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out

...

gcc -I/usr/share/R/include -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I. -Iinclude -std=gnu99 -O3 -pipe -g -fpic -std=gnu99 -O3 -pipe -g -c w32-backend.c -o w32-backend.o
gcc -I/usr/share/R/include -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I. -Iinclude -std=gnu99 -O3 -pipe -g -fpic -std=gnu99 -O3 -pipe -g -c xlib-backend.c -o xlib-backend.o
gcc -shared -o Cairo.so cairobem.o cairogd.o cairotalk.o img-backend.o img-jpeg.o img-tiff.o pdf-backend.o ps-backend.o svg-backend.o w32-backend.o xlib-backend.o -lfreetype -lfontconfig -lpng12 -lz -lXrender -lcairo -lX11 -ljpeg -L/usr/lib64/R/lib -lR
installing to /usr/local/lib/R/site-library/Cairo/libs
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices ...
** testing if installed package can be loaded

* DONE (Cairo)

The downloaded packages are in
'/tmp/Rtmpv9s866/downloaded_packages'
Ten wpis został opublikowany w kategorii Linux. Dodaj zakładkę do bezpośredniego odnośnika.