From 29d9a509bf86ec1e3862a91853255deb0ee4b6cc Mon Sep 17 00:00:00 2001 From: stephen Date: Fri, 13 Jul 2007 15:41:23 +0000 Subject: [PATCH] (ess-r-version-date): New defun, replacing ess-r-version-time as it returns the date stamp of R as a string rather than a time in seconds. (ess-find-newest-date): New defun, replacing ess-which-newest-date. git-svn-id: https://svn.r-project.org/ESS/trunk@3741 0bbaf3bd-34e0-0310-bf65-c717079852d4 --- lisp/essd-r.el | 80 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/lisp/essd-r.el b/lisp/essd-r.el index 369d29fc..666c583c 100644 --- a/lisp/essd-r.el +++ b/lisp/essd-r.el @@ -236,60 +236,58 @@ This function was generated by `ess-r-versions-create'.\" -;; SJE: 2007-07-11 -- Perhaps this implementation should use an alist -;; rather than two lists, one for version names, and one for version times? -;; e.g. '( ("R-1.9" . 2000) ("R-2.0" . 3000) ("R-devel" . 5000)) - -;; (ess-r-version-time "R-1.9") -(defun ess-r-version-time (rver) - "Return the time of the version of R named RVER. -The time is returned in seconds, to allow comparisons between -different versions of R. If the version of R could not be found -from the output of the RVER program, -1 is returned." + +;; (ess-r-version-date "R-1.9") +(defun ess-r-version-date (rver) + "Return the date of the version of R named RVER. +The date is returned as a date string. If the version of R could +not be found from the output of the RVER program, \"-1\" is +returned." (let (ver-string - date - (time -1)) + (date "-1")) (setq ver-string (shell-command-to-string (concat rver " --version"))) (when (string-match "R version [^\n\(]+ (\\([0-9-]+\\))" ver-string) - (setq date (match-string 1 ver-string)) - (setq time (time-to-seconds - (apply #'encode-time - (mapcar '(lambda (x) (if x x 0)) - (parse-time-string date)))))) - time) - - ) + (setq date (match-string 1 ver-string))) + (cons date rver))) (defun ess-newest-r (rvers) "Check all the versions of RVERS to see which is the newest. Create an alias for that version of R, so that M-x R-newest will run it." (let ( rnewest - (rtimes (mapcar 'ess-r-version-time rvers))) - (setq rnewest (ess-which-newest rtimes rvers)) + (rtimes (mapcar 'ess-r-version-date rvers))) + (setq rnewest (ess-find-newest-date rtimes)) (fset 'R-newest (intern rnewest)) + ;; SJE: 2007-07-13 -- following line is a temp var to check that + ;; the newest version of R is found correctly. + (setq temp-ess-newest rtimes) (message (concat "newest is " rnewest)))) -(defun ess-which-newest (times rver) - "Find the most recent version of RVER by seeing which of the corresponding -element of TIMES is newest (largest). The time for each version of R is -computed by `ess-r-version-time'." - (let - ( newest-time newest-ver) - (setq newest-time (car times) - times (cdr times)) - (setq newest-ver (car rver) - rver (cdr rver)) - (while times - (setq this-num (car times) - this-ver (car rver) - times (cdr times) - rver (cdr rver)) - (when (> this-num newest-time) - (setq newest-ver this-ver - newest-time this-num))) - newest-ver)) +;; Test case for following defun: +;; (setq a '( ("2003-10-04" . "R-1.7") +;; ("2006-11-19" . "R-2.2") +;; ("2007-07-01" . "R-dev") +;; ("-1" . "R-broken") +;; ("2005-12-30" . "R-2.0"))) +;; (ess-find-newest-date a) +(defun ess-find-newest-date (rvers) + "Find the newest version of R given in the a-list RVERS. +Each element of RVERS is a dotted pair (date . R-version), where +date is given as e.g.\"2007-11-30\" so that we can compare dates +as strings. If a date is listed as \"-1\", that version of R +could not be found. + +If the value returned is nil, no valid newest version of R could be found." + (let (new-r + (new-time "0")) + (while rvers + (setq this-r (car rvers) + rvers (cdr rvers)) + (when (string< new-time (car this-r)) + (setq new-time (car this-r) + new-r (cdr this-r)))) + new-r)) (defun ess-find-rterm (&optional ess-R-root-dir) -- 2.11.4.GIT