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

;;"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 recent
  (call-with-values
      (lambda ()
        (http-get "https://cran.r-project.org/web/packages/available_packages_by_date.html"))
    (lambda (response body)
      ((sxpath '(// table * td a *text*))
       (html->sxml body)))))

(define all recent)

(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 Wed Sep 28 11:54:28 2022. CEST. (original)