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.
(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 '...))