(import (htmlprag)
        (sxml xpath)
        (gnu packages)
        (guix packages)
        (guix import cran)
        (guix import utils)
        (srfi srfi-1)
        (ice-9 pretty-print))


;;"https://cran.r-project.org/web/packages/available_packages_by_name.html"

(define sxml
  (call-with-input-file
      "/home/rekado/dev/gx/branches/master/available_packages_by_name.html"
    html->sxml))

(define all
  ((sxpath '(* * table * td a *text*)) sxml))

(define existing
  (fold-packages
   (lambda (pkg res)
     (if (eq? (package-build-system pkg)
              (@ (guix build-system r) r-build-system))
         (cons (or (and=> (package-properties pkg)
                          (lambda (prop)
                            (assoc-ref prop 'upstream-name)))
                   (string-drop (package-name pkg) 2))
               res)
         res))
   (list)))

(define missing
  (lset-difference string= all existing))

(pk 'missing (length missing))

(define (import-from-cran names)
  (append-map
   (lambda (name)
     (map package->definition
          (filter identity (cran-recursive-import name))))
   names))

(pretty-print (import-from-cran (take (reverse missing) 5)))

Generated by Ricardo Wurmus using scpaste at Tue Sep 27 17:33:00 2022. CEST. (original)