add *r-interactive* variable -- set to 1 if working interactively in Common Lisp
[rclg.git] / src / rclg-load.lisp
blob85e0243ed865152e820d5eaa7e412c53b25d1233
1 ;;; RCLG: R-CommonLisp Gateway
3 ;;; Copyright (c) 2005--2007, <rif@mit.edu>
4 ;;; AJ Rossini <blindglobe@gmail.com>
5 ;;; All rights reserved.
6 ;;;
7 ;;; Redistribution and use in source and binary forms, with or without
8 ;;; modification, are permitted provided that the following conditions are
9 ;;; met:
10 ;;;
11 ;;; * Redistributions of source code must retain the above copyright
12 ;;; notice, this list of conditions and the following disclaimer.
13 ;;; * Redistributions in binary form must reproduce the above
14 ;;; copyright notice, this list of conditions and the following disclaimer
15 ;;; in the documentation and/or other materials provided with the
16 ;;; distribution.
17 ;;; * The names of the contributors may not be used to endorse or
18 ;;; promote products derived from this software without specific
19 ;;; prior written permission.
20 ;;;
21 ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 ;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 ;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 ;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 ;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 ;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 ;;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 ;;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 ;;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 ;;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 ;;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ;;; Author: rif@mit.edu
34 ;;; Maintainers: rif@mit.edu,
35 ;;; AJ Rossini <blindglobe@gmail.com>
37 ;;; Intent: initialize environment stuff. Purely developer level, no
38 ;;; user tools.
40 (defpackage :rclg-load
41 (:use :common-lisp :cffi :rclg-cffi-sysenv)
42 (:export load-r-libraries *rclg-loaded*))
44 (in-package :rclg-load)
46 ;;;* Variables for RCLG state/location
48 (defvar *rclg-loaded* nil
49 "True once rclg is loaded, nil otherwise (including errors).")
51 ;; The user MUST make sure *R-HOME-STR* points to the right place!
52 ;; --rif
54 ;; AJR: we do this by testing directories existence. Rif's is first,
55 ;; Debian's is second. A better way to do this would be to check that
56 ;; the library exists, but we could do that later if we don't need
58 (eval-when (:compile-toplevel :load-toplevel)
59 (defvar *R-HOME-STR*
60 (namestring
61 (cond
62 ;; this is made confusing -- SBCL is lax and lets us use
63 ;; probe-file, but CLISP is more rigourous and forces an error
64 ;; in such cases.
65 #+sbcl((probe-file #p"/home/rif/RCLG-test/R-2.3.1/"))
66 #+sbcl((probe-file #p"/usr/lib/R/"))
67 #+clisp((ext:probe-directory #p"/home/rif/RCLG-test/R-2.3.1/"))
68 #+clisp((ext:probe-directory #p"/usr/lib/R/"))
69 (t (error "R not found."))))))
71 (posix-setenv "R_HOME" *R-HOME-STR* 1)
74 ;;(setf *rclg-loaded* nil)
76 (defun load-r-libraries ()
77 (unless *rclg-loaded*
78 (progn
79 (define-foreign-library libR
80 (t (:default #.(concatenate 'string *R-HOME-STR* "/lib/libR"))))
81 (use-foreign-library libR)
82 ;; (load-foreign-library libR)
83 (setf *rclg-loaded* t))))
85 ;; (load-foreign-library "/usr/lib/R/lib/libR.so")
87 ;; *rclg-loaded*
88 ;; (load-r-libraries)