Changeset: 1e8b5e316b3c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1e8b5e316b3c
Added Files:
monetdb5/extras/rapi/Tests/rapi06.stable.err
monetdb5/extras/rapi/Tests/rapi06.stable.out
monetdb5/extras/rapi/rapi.R
Modified Files:
monetdb5/extras/rapi/Makefile.ag
monetdb5/extras/rapi/rapi.c
monetdb5/mal/mal_linker.c
monetdb5/mal/mal_linker.h
Branch: RIntegration
Log Message:
R API: Environment setup script with package auto-installer, fixes rapi06.mal
test case. Approved rapi06.mal test output.
diffs (232 lines):
diff --git a/monetdb5/extras/rapi/Makefile.ag b/monetdb5/extras/rapi/Makefile.ag
--- a/monetdb5/extras/rapi/Makefile.ag
+++ b/monetdb5/extras/rapi/Makefile.ag
@@ -43,6 +43,12 @@ headers_rapi_mal = {
SOURCES = rapi.mal
}
+headers_rapi_R = {
+ HEADERS = R
+ DIR = libdir/monetdb5
+ SOURCES = rapi.R
+}
+
headers_autoload = {
HEADERS = mal
DIR = libdir/monetdb5/autoload
@@ -50,4 +56,4 @@ headers_autoload = {
}
EXTRA_DIST_DIR = Tests
-EXTRA_DIST = 50_rapi.mal rapi.mal
+EXTRA_DIST = 50_rapi.mal rapi.mal rapi.R
diff --git a/monetdb5/extras/rapi/Tests/rapi06.stable.err
b/monetdb5/extras/rapi/Tests/rapi06.stable.err
new file mode 100644
--- /dev/null
+++ b/monetdb5/extras/rapi/Tests/rapi06.stable.err
@@ -0,0 +1,29 @@
+stderr of test 'rapi06` in directory 'monetdb5/extras/rapi` itself:
+
+
+# 19:19:06 >
+# 19:19:06 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set"
"mapi_open=true" "--set" "mapi_port=39439" "--set"
"mapi_usock=/var/tmp/mtest-4063/.s.monetdb.39439" "--set" "monet_prompt="
"--forcemito" "--set" "mal_listing=2"
"--dbpath=/export/scratch2/hannes/monetdb-rint-install/var/MonetDB/mTests_monetdb5_extras_rapi"
"rapi06.mal"
+# 19:19:06 >
+
+# builtin opt gdk_dbpath =
/export/scratch2/hannes/monetdb-rint-install/var/monetdb5/dbfarm/demo
+# builtin opt gdk_debug = 0
+# builtin opt gdk_vmtrim = yes
+# builtin opt monet_prompt = >
+# builtin opt monet_daemon = no
+# builtin opt mapi_port = 50000
+# builtin opt mapi_open = false
+# builtin opt mapi_autosense = false
+# builtin opt sql_optimizer = default_pipe
+# builtin opt sql_debug = 0
+# cmdline opt gdk_nr_threads = 0
+# cmdline opt mapi_open = true
+# cmdline opt mapi_port = 39439
+# cmdline opt mapi_usock = /var/tmp/mtest-4063/.s.monetdb.39439
+# cmdline opt monet_prompt =
+# cmdline opt mal_listing = 2
+# cmdline opt gdk_dbpath =
/export/scratch2/hannes/monetdb-rint-install/var/MonetDB/mTests_monetdb5_extras_rapi
+
+# 19:19:06 >
+# 19:19:06 > "Done."
+# 19:19:06 >
+
diff --git a/monetdb5/extras/rapi/Tests/rapi06.stable.out
b/monetdb5/extras/rapi/Tests/rapi06.stable.out
new file mode 100644
--- /dev/null
+++ b/monetdb5/extras/rapi/Tests/rapi06.stable.out
@@ -0,0 +1,46 @@
+stdout of test 'rapi06` in directory 'monetdb5/extras/rapi` itself:
+
+
+# 19:19:06 >
+# 19:19:06 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set"
"mapi_open=true" "--set" "mapi_port=39439" "--set"
"mapi_usock=/var/tmp/mtest-4063/.s.monetdb.39439" "--set" "monet_prompt="
"--forcemito" "--set" "mal_listing=2"
"--dbpath=/export/scratch2/hannes/monetdb-rint-install/var/MonetDB/mTests_monetdb5_extras_rapi"
"rapi06.mal"
+# 19:19:06 >
+
+# MonetDB 5 server v11.18.0
+# This is an unreleased version
+# Serving database 'mTests_monetdb5_extras_rapi', using 8 threads
+# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs dynamically
linked
+# Found 15.592 GiB available main-memory.
+# Copyright (c) 1993-July 2008 CWI.
+# Copyright (c) August 2008-2014 MonetDB B.V., all rights reserved
+# Visit http://www.monetdb.org/ for further information
+# Listening for connection requests on mapi:monetdb://bristol.ins.cwi.nl:39439/
+# Listening for UNIX domain connection requests on
mapi:monetdb:///var/tmp/mtest-4063/.s.monetdb.39439
+# MonetDB/GIS module loaded
+# MonetDB/JAQL module loaded
+# MonetDB/SQL module loaded
+function user.main():void;
+ ts := bat.new(:oid,:int);
+ bat.append(ts,1387360138);
+ bat.append(ts,451665720);
+ bat.append(ts,514382400);
+ bat.append(ts,1000209600);
+ bat.append(ts,1326272400);
+ r:bat[:oid,:int] :=
rapi.eval("library(moonsun);options(latitude=arg2,longitude=arg3);angles <-
sapply(arg1,FUN=function(x){ts <- as.POSIXlt(x,origin =
\"1970-01-01\",tz=\"UTC\");moon(jd(epoch=ts)+ts$hour/24)$angle});return(arg1[angles
> 0])",ts,52.2999992,4.80000019);
+ io.print(r);
+end main;
+# User R expression:
library(moonsun);options(latitude=arg2,longitude=arg3);angles <-
sapply(arg1,FUN=function(x){ts <- as.POSIXlt(x,origin =
"1970-01-01",tz="UTC");moon(jd(epoch=ts)+ts$hour/24)$angle});return(arg1[angles
> 0])
+# Executed R expression ret <-
as.data.frame((function(arg1,arg2,arg3){library(moonsun);options(latitude=arg2,longitude=arg3);angles
<- sapply(arg1,FUN=function(x){ts <- as.POSIXlt(x,origin =
"1970-01-01",tz="UTC");moon(jd(epoch=ts)+ts$hour/24)$angle});return(arg1[angles
> 0])})(arg1,arg2,arg3),nm=NA,stringsAsFactors=F)
+
+#--------------------------#
+# h t # name
+# void int # type
+#--------------------------#
+[ 0@0, 1387360138 ]
+[ 1@0, 451665720 ]
+[ 2@0, 1000209600 ]
+[ 3@0, 1326272400 ]
+
+# 19:19:06 >
+# 19:19:06 > "Done."
+# 19:19:06 >
+
diff --git a/monetdb5/extras/rapi/rapi.R b/monetdb5/extras/rapi/rapi.R
new file mode 100644
--- /dev/null
+++ b/monetdb5/extras/rapi/rapi.R
@@ -0,0 +1,40 @@
+# The contents of this file are subject to the MonetDB Public License
+# Version 1.1 (the "License"); you may not use this file except in
+# compliance with the License. You may obtain a copy of the License at
+# http://www.monetdb.org/Legal/MonetDBLicense
+#
+# Software distributed under the License is distributed on an "AS IS"
+# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+# License for the specific language governing rights and limitations
+# under the License.
+#
+# The Original Code is the MonetDB Database System.
+#
+# The Initial Developer of the Original Code is CWI.
+# Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+# Copyright August 2008-2014 MonetDB B.V.
+# All Rights Reserved.
+
+# R environment adaptions for MonetDB-embedded operations
+
+# auto-install packages by intercepting library()
+.library.original <- library
+
+library <- function(package, help, pos = 2, lib.loc = NULL, character.only =
FALSE,
+ logical.return = FALSE, warn.conflicts = TRUE, quietly = FALSE,
+ verbose = getOption("verbose")) {
+
+ package <- as.character(substitute(package))
+ if (!(package %in% installed.packages()[,"Package"]))
+ install.packages(package,repos=c("http://cran.rstudio.com/"))
+
+
.library.original(package,help,pos,lib.loc,character.only=T,logical.return,warn.conflicts,quietly)
+}
+
+# do not re-install existing packages if install.packages() is called
+install.packages.original <- install.packages
+# TODO how to check version etc?
+
+# redirect default graphics device to PDF
+options(device="pdf")
+# where should plot files be written to?
diff --git a/monetdb5/extras/rapi/rapi.c b/monetdb5/extras/rapi/rapi.c
--- a/monetdb5/extras/rapi/rapi.c
+++ b/monetdb5/extras/rapi/rapi.c
@@ -22,6 +22,10 @@
* The R interface
*/
#include "monetdb_config.h"
+#include "mal.h"
+#include "mal_stack.h"
+#include "mal_linker.h"
+
#include "rapi.h"
//
// R headers
@@ -117,19 +121,42 @@ void writeConsoleEx(const char * buf, in
}
static void RAPIinitialize(void) {
- char *rargv[] = { "whatever", "--quiet", "--no-save", "--vanilla" };
+ char *rargv[] = { "whatever", "--quiet", "--no-save",
"--no-restore-data" };
char* rhome = "/usr/lib64/R"; // TODO: get this from ./configure or a
call to system()
+ int evalErr;
+ ParseStatus status;
+ char rlibs[BUFSIZ];
+ char rapiinclude[BUFSIZ];
+
+
MT_lock_init(&rapiLock, "rapi_lock");
+
+ snprintf(rlibs, BUFSIZ, "%s%c%s%c%s%c%s",
+ LOCALSTATEDIR, DIR_SEP, "monetdb5", DIR_SEP, "rapi",
+ DIR_SEP, "libs");
+
+ snprintf(rapiinclude, BUFSIZ, "source(\"%s\")",
+ locate_file("rapi",".R",0));
+
setenv("R_HOME",rhome,TRUE);
+ setenv("R_LIBS_USER",rlibs,TRUE);
+
R_SignalHandlers = 0;
Rf_initEmbeddedR(4, rargv);
- // these globals are indicative for non-thread safe R settings.
+
ptr_R_WriteConsole = writeConsole;
ptr_R_WriteConsoleEx = writeConsoleEx;
R_Outputfile = NULL;
R_Consolefile = NULL;
+
+ // run the R environment initialization script rapi.R
+ R_tryEval(
+ VECTOR_ELT(
+ R_ParseVector(
+ mkString(rapiinclude),1, &status, R_NilValue),
0),R_GlobalEnv,&evalErr);
+
rapiInitialized++;
}
diff --git a/monetdb5/mal/mal_linker.c b/monetdb5/mal/mal_linker.c
--- a/monetdb5/mal/mal_linker.c
+++ b/monetdb5/mal/mal_linker.c
@@ -389,7 +389,7 @@ cmpstr(const void *_p1, const void *_p2)
#define MAXMULTISCRIPT 48
-static char *
+char *
locate_file(const char *basename, const char *ext, bit recurse)
{
char *mod_path = GDKgetenv("monet_mod_path");
diff --git a/monetdb5/mal/mal_linker.h b/monetdb5/mal/mal_linker.h
--- a/monetdb5/mal/mal_linker.h
+++ b/monetdb5/mal/mal_linker.h
@@ -42,4 +42,5 @@ mal_export void unloadLibraries(void);
mal_export void initLibraries(void);
mal_export int isPreloaded(str nme);
mal_export int isLoaded(str modulename);
+mal_export char *locate_file(const char *basename, const char *ext, bit
recurse);
#endif /* _MAL_LINKER_H */
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list