unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
From: divoplade <d@divoplade.fr>
To: Ricardo Wurmus <rekado@elephly.net>, zimoun <zimon.toutoune@gmail.com>
Cc: help-guix@gnu.org
Subject: Re: Wrapping an R script: how do I compose the R_LIBS_SITE environment variable?
Date: Sun, 07 Feb 2021 01:24:53 +0100	[thread overview]
Message-ID: <e5ffcd89fcc2211d9934bccd97fd8c92122c434d.camel@divoplade.fr> (raw)
In-Reply-To: <87ft29tdu5.fsf@elephly.net>

[-- Attachment #1: Type: text/plain, Size: 891 bytes --]

Hello,

Sorry, I realize I was not clear enough.

Attached is an example of a script written in R that has non-trivial
recursive dependencies.

You can run the example as:

guix environment --ad-hoc --container -l package.scm -- hello
You will normally see something like:

$ guix environment --ad-hoc --container -l /tmp/package.scm -- hello
# A tibble: 10 x 2
       x     y
   <int> <dbl>
 1     1     1
 2     2     4
 3     3     9
 4     4    16
 5     5    25
 6     6    36
 7     7    49
 8     8    64
 9     9    81
10    10   100
sh: rm: command not found

If you look at the package definition, you see that I call wrap-program 
in order to set the R_LIBS_SITE environment variable. The components of
R_LIBS_SITE is the R dependencies of my package, and their recursive R
dependencies. But I don't know how to get them.

I hope this example is better at explaining the problem.

[-- Attachment #2: package.scm --]
[-- Type: text/x-scheme, Size: 2051 bytes --]

(use-modules (guix packages)
	     (guix build-system trivial)
	     (guix gexp)
	     (gnu packages base)
	     (gnu packages bash)
	     (gnu packages statistics)
	     (gnu packages cran))

(package
 (name "r-hello")
 (version "0.0.0")
 (source (plain-file "empty" ""))
 (build-system trivial-build-system)
 (arguments
  '(#:modules ((guix build utils))
    #:builder
    (begin
      (use-modules (guix build utils))
      (let ((out (assoc-ref %outputs "out"))
	    (r-in (assoc-ref %build-inputs "r-minimal"))
	    (bash-in (assoc-ref %build-inputs "bash")))
	(mkdir out)
	(mkdir (string-append out "/bin"))
	;; Bug? PATH is not set
	(setenv "PATH" (string-append bash-in "/bin"))
	(call-with-output-file (string-append out "/bin/hello")
	  (lambda (port)
	    (format port "#!~a/bin/Rscript

library (\"magrittr\")

data <- (tibble::tibble (x = 1:10)
    %>% dplyr::mutate (y = x ^ 2))

print (data)
"
		    r-in)))
	(chmod (string-append out "/bin/hello") #o755)
	(wrap-program
	 (string-append out "/bin/hello")
	 `("R_LIBS_SITE" ":" =
	   ,(map (lambda (r-package)
		   ;; R_LIBS_SITE should point to the site-library
		   ;; folder of the packages
		   (string-append (assoc-ref %build-inputs r-package)
				  "/site-library"))
		 ;; Here are my R dependencies:
		 '("r-magrittr" "r-tibble" "r-dplyr"
		   ;; However, running hello requires these recursive
		   ;; dependencies. How am I supposed to know? What if
		   ;; they change with future versions of my
		   ;; dependencies?
		   "r-rlang" "r-vctrs" "r-r6" "r-generics" "r-glue"
		   "r-lifecycle" "r-ellipsis" "r-pillar" "r-crayon"
		   "r-pkgconfig" "r-tidyselect" "r-purrr" "r-cli"
		   "r-assertthat" "r-fansi" "r-utf8"))))))))
 (native-inputs
  `(("bash" ,bash)))
 (inputs
  `(("r-minimal" ,r-minimal)
    ("bash" ,bash)))
 (propagated-inputs
  `(("r-magrittr" ,r-magrittr)
    ("r-tibble" ,r-tibble)
    ("r-dplyr" ,r-dplyr)))
 (synopsis "A script written in R")
 (description "How can I list the recursive R dependencies?")
 (home-page "http://example.com")
 (license '...))

  reply	other threads:[~2021-02-07  0:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05 16:14 Wrapping an R script: how do I compose the R_LIBS_SITE environment variable? divoplade
2021-02-06 13:53 ` zimoun
2021-02-06 15:28   ` Ricardo Wurmus
2021-02-07  0:24     ` divoplade [this message]
2021-02-07  7:11       ` Ricardo Wurmus
2021-02-07  9:30         ` divoplade
2021-02-07 15:03           ` zimoun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e5ffcd89fcc2211d9934bccd97fd8c92122c434d.camel@divoplade.fr \
    --to=d@divoplade.fr \
    --cc=help-guix@gnu.org \
    --cc=rekado@elephly.net \
    --cc=zimon.toutoune@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).