├── .gitignore ├── README.md ├── Rserve ├── DESCRIPTION ├── INDEX ├── LICENSE ├── NAMESPACE ├── NEWS ├── R │ └── conn.R ├── clients.txt ├── configure ├── configure.ac ├── configure.win ├── man │ ├── Rclient.Rd │ └── Rserv.Rd ├── src │ ├── Makefile.in │ ├── Makefile.win │ ├── Rserv.c │ ├── Rsrv.h │ ├── client │ │ ├── README.txt │ │ ├── cxx │ │ │ ├── COPYING │ │ │ ├── Makefile │ │ │ ├── Makefile.in │ │ │ ├── Makefile.win │ │ │ ├── Rconnection.cc │ │ │ ├── Rconnection.h │ │ │ ├── ReadMe.txt │ │ │ ├── Rsrv.h │ │ │ ├── config.h │ │ │ ├── config.h.in │ │ │ ├── config.status │ │ │ ├── configure │ │ │ ├── configure.ac │ │ │ ├── demo1.cc │ │ │ ├── demo1.xx │ │ │ ├── rcmd.cc │ │ │ ├── rcons.cc │ │ │ ├── rsdown.cc │ │ │ └── sisocks.h │ │ ├── java-new │ │ │ ├── JRI │ │ │ │ ├── JRIEngine.java │ │ │ │ ├── Makefile │ │ │ │ ├── package-info.java │ │ │ │ └── test │ │ │ │ │ ├── Makefile │ │ │ │ │ └── RTest.java │ │ │ ├── LICENSE │ │ │ ├── Makefile │ │ │ ├── MutableREXP.java │ │ │ ├── REXP.java │ │ │ ├── REXPDouble.java │ │ │ ├── REXPEnvironment.java │ │ │ ├── REXPExpressionVector.java │ │ │ ├── REXPFactor.java │ │ │ ├── REXPGenericVector.java │ │ │ ├── REXPInteger.java │ │ │ ├── REXPLanguage.java │ │ │ ├── REXPList.java │ │ │ ├── REXPLogical.java │ │ │ ├── REXPMismatchException.java │ │ │ ├── REXPNull.java │ │ │ ├── REXPRaw.java │ │ │ ├── REXPReference.java │ │ │ ├── REXPS4.java │ │ │ ├── REXPString.java │ │ │ ├── REXPSymbol.java │ │ │ ├── REXPUnknown.java │ │ │ ├── REXPVector.java │ │ │ ├── REXPWrapper.java │ │ │ ├── REngine.java │ │ │ ├── REngineCallbacks.java │ │ │ ├── REngineConsoleHistoryInterface.java │ │ │ ├── REngineEvalException.java │ │ │ ├── REngineException.java │ │ │ ├── REngineInputInterface.java │ │ │ ├── REngineOutputInterface.java │ │ │ ├── REngineStdOutput.java │ │ │ ├── REngineUIInterface.java │ │ │ ├── RFactor.java │ │ │ ├── RList.java │ │ │ ├── Rserve │ │ │ │ ├── Makefile │ │ │ │ ├── RConnection.java │ │ │ │ ├── RFileInputStream.java │ │ │ │ ├── RFileOutputStream.java │ │ │ │ ├── RSession.java │ │ │ │ ├── RserveException.java │ │ │ │ ├── package-info.java │ │ │ │ ├── protocol │ │ │ │ │ ├── REXPFactory.java │ │ │ │ │ ├── RPacket.java │ │ │ │ │ ├── RTalk.java │ │ │ │ │ └── jcrypt.java │ │ │ │ └── test │ │ │ │ │ ├── Makefile │ │ │ │ │ ├── PlotDemo.java │ │ │ │ │ ├── StartRserve.java │ │ │ │ │ ├── jt.java │ │ │ │ │ └── test.java │ │ │ └── package-info.java │ │ ├── java-old │ │ │ ├── LICENSE │ │ │ ├── Makefile │ │ │ ├── RBool.java │ │ │ ├── REXP.java │ │ │ ├── RFactor.java │ │ │ ├── RFileInputStream.java │ │ │ ├── RFileOutputStream.java │ │ │ ├── RList.java │ │ │ ├── RSession.java │ │ │ ├── RSrvException.java │ │ │ ├── Rconnection.java │ │ │ ├── Rpacket.java │ │ │ ├── Rtalk.java │ │ │ ├── examples │ │ │ │ ├── Makefile │ │ │ │ ├── PlotDemo.java │ │ │ │ ├── jt.java │ │ │ │ ├── t.java │ │ │ │ └── tt.java │ │ │ ├── jcrypt.java │ │ │ └── package-info.java │ │ └── php │ │ │ └── simple.php │ ├── config.h │ ├── config.h.in │ ├── include │ │ ├── Parse.h │ │ ├── Win32 │ │ │ ├── Startup.h │ │ │ ├── config.h │ │ │ └── psignal.h │ │ ├── sbthread.h │ │ └── sisocks.h │ ├── m.sh │ ├── md5.c │ ├── md5.h │ ├── mergefat │ ├── session.c │ ├── session.h │ └── winembed.c └── version ├── RserveVisualStudio ├── RPackage │ └── RPackage.vcxproj ├── Rserve.sdf ├── Rserve.sln └── Rserve │ ├── R.lib │ ├── Rserve.vcxproj │ ├── banned.h │ └── generate_R_lib.bat └── SECURITY.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore extensions 2 | *.diff 3 | *.err 4 | *.log 5 | *.orig 6 | *.rej 7 | *.swo 8 | *.swp 9 | *.vi 10 | *.zip 11 | *~ 12 | 13 | # Ignore OS or Editor folders 14 | ._* 15 | .cache 16 | .DS_Store 17 | .project 18 | .settings 19 | .idea 20 | .tmproj 21 | *.esproj 22 | *.sublime-workspace 23 | *.sublime-project 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | deployr-rserve 2 | ============== 3 | 4 | `deployr-rserve` is a fork of the popular R package, [Rserve](https://github.com/s-u/Rserve), from Simon Urbanek. 5 | 6 | This fork is based on Rserve `0.6-3.1` and adds the following features: 7 | 8 | 1. Concurrent R sessions under Rserve on the Windows platform 9 | 1. Ability to switch the execution context of the Rserve process to a specified uid/gid 10 | 1. Out-of-band control socket that supports a cancel operation on any Rserve eval operation 11 | 12 | Installations of DeployR require `deployr-rserve`. The standard [Rserve](https://github.com/s-u/Rserve) package does not include the necessary functionality to work with [DeployR](https://github.com/deployr/server). 13 | -------------------------------------------------------------------------------- /Rserve/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: deployrRserve 2 | Version: 9.0.0 3 | Title: Binary R server 4 | Author: Simon Urbanek 5 | Maintainer: Simon Urbanek 6 | Depends: R (>= 1.5.0) 7 | SystemRequirements: R must be compiled with --enable-R-shlib if the server is to be built 8 | Description: Rserve acts as a socket server (TCP/IP or local sockets) 9 | which allows binary requests to be sent to R. Every 10 | connection has a separate workspace and working 11 | directory. Client-side implementations are available 12 | for popular languages such as C/C++ and Java, allowing 13 | any application to use facilities of R without the need of 14 | linking to R code. Rserve supports remote connection, 15 | user authentication and file transfer. A simple R client 16 | is included in this package as well. 17 | License: GPL version 2 18 | URL: http://www.rforge.net/Rserve/ 19 | -------------------------------------------------------------------------------- /Rserve/INDEX: -------------------------------------------------------------------------------- 1 | Rserve Server providing R functionality to 2 | applications via TCP/IP 3 | -------------------------------------------------------------------------------- /Rserve/NAMESPACE: -------------------------------------------------------------------------------- 1 | exportPattern("^[[:alpha:]]+") 2 | -------------------------------------------------------------------------------- /Rserve/clients.txt: -------------------------------------------------------------------------------- 1 | Rserve is a binary R server that listens to clients and processes 2 | their requests. The Rserve package primarity builds the server which 3 | can be the started using R CMD Rserve or via the Rserve() function in 4 | R. 5 | 6 | Clients programs that connect to a running Rserve and submit requests 7 | for computation. The Rserve protocol is open source, so anyone is free 8 | to write a client, but Rserve package comes with three clients: 9 | 10 | - Java client in src/client/java 11 | - C++ client in src/client 12 | - simple R client part of the Rserve R package 13 | 14 | 15 | Java client 16 | ============= 17 | 18 | The most sophisticated client is the Java client which allows any Java 19 | application to use R facilities without linking directly to R. It 20 | supports the full range of Rserve functionality and is located in 21 | 22 | src/client/java 23 | 24 | It can be compiled into a JAR file by typing "make" in the 25 | src/client/java directory. The resulting file JRcleint.jar is all that 26 | is needed. JavaDoc documentation can be generated using "make doc". 27 | 28 | 29 | C++ client 30 | ============ 31 | 32 | The C++ client is located in the src/client directory and will be 33 | compiled if --with-client is specified upon installation. 34 | Alternatively it can be compiled manually by typing "make" in 35 | src/client after configure script was run. See ReadMe.txt in 36 | src/client for details. 37 | 38 | 39 | R client 40 | ========== 41 | 42 | The Rserve package also includes a simple R client, i.e. it allows you 43 | to connect to Rserve from R itself. It is very simple and limited, 44 | because Rserve was not primarily meant for R-to-R communication (there 45 | are better ways to do that), but it is useful for quick interactive 46 | connection to an Rserve farm. See ?RSconnect in R after loading the 47 | Rserve package. 48 | 49 | 50 | --- 51 | Simon Urbanek, 2006-11-30 52 | -------------------------------------------------------------------------------- /Rserve/configure.ac: -------------------------------------------------------------------------------- 1 | # Process this file with autoconf to produce a configure script. 2 | AC_INIT([Rserve],[0.4],[Simon.Urbanek@r-project.org]) 3 | AC_CONFIG_SRCDIR([src/Rserv.c]) 4 | AC_CONFIG_HEADER([src/config.h]) 5 | 6 | # find R home and set CC/CFLAGS 7 | : ${R_HOME=`R RHOME`} 8 | if test -z "${R_HOME}"; then 9 | echo "could not determine R_HOME" 10 | exit 1 11 | fi 12 | 13 | AC_ARG_WITH([server], 14 | AS_HELP_STRING(--with-server,[compile Rserve server (default is @<:@yes@:>@). Given that this is the main functionality of Rserve, the only reason to disable the server is to configure R or C++ client separately.]), 15 | [with_server=$withval], [with_server=yes]) 16 | 17 | AC_ARG_WITH([client], 18 | AS_HELP_STRING(--with-client,[compile additional C/C++ Rserve client (default is @<:@no@:>@). The client can be always compiled manually regardless of this setting.]), 19 | [with_client=$withval], [with_client=no]) 20 | 21 | RLD=`${R_HOME}/bin/R CMD config --ldflags 2>/dev/null` 22 | has_R_shlib=no 23 | if test -n "$RLD"; then 24 | has_R_shlib=yes 25 | fi 26 | 27 | AC_MSG_CHECKING([whether to compile the server]) 28 | if test "${with_server}" = yes; then 29 | AC_MSG_RESULT(yes) 30 | if test "${has_R_shlib}" = no; then 31 | AC_MSG_ERROR([R was configured without --enable-R-shlib or --enable-R-static-lib 32 | 33 | *** Rserve requires R (shared or static) library. *** 34 | *** Please install R library or compile R with either --enable-R-shlib *** 35 | *** or --enable-R-static-lib support *** 36 | 37 | Alternatively use --without-server if you wish to build only Rserve client. 38 | 39 | ]) 40 | fi 41 | else 42 | AC_MSG_RESULT(no) 43 | fi 44 | 45 | AC_MSG_CHECKING([whether to compile the client]) 46 | if test "${with_client}" = yes; then 47 | AC_MSG_RESULT(yes) 48 | else 49 | AC_MSG_RESULT(no) 50 | fi 51 | 52 | AM_CONDITIONAL(WITH_SERVER, [test "x${with_server}" = xyes]) 53 | AM_CONDITIONAL(WITH_CLIENT, [test "x${with_client}" = xyes]) 54 | 55 | CC=`${R_HOME}/bin/R CMD config CC`; 56 | CXX=`${R_HOME}/bin/R CMD config CXX`; 57 | CPPFLAGS="${CPPFLAGS} ${PKG_CPPFLAGS}" 58 | CFLAGS=`${R_HOME}/bin/R CMD config CFLAGS` 59 | CXXFLAGS=`${R_HOME}/bin/R CMD config CXXFLAGS` 60 | RINC=`${R_HOME}/bin/R CMD config --cppflags` 61 | AC_SUBST(R_HOME) 62 | AC_SUBST(RINC) 63 | AC_SUBST(RLD) 64 | 65 | # Checks for programs. 66 | AC_PROG_CC 67 | 68 | # Checks for libraries. 69 | 70 | # Checks for header files. 71 | AC_HEADER_STDC 72 | AC_HEADER_SYS_WAIT 73 | AC_CHECK_HEADERS([string.h memory.h sys/time.h unistd.h]) 74 | AC_CHECK_HEADERS([sys/stat.h sys/types.h sys/socket.h sys/un.h netinet/in.h netinet/tcp.h]) 75 | 76 | # Checks for typedefs, structures, and compiler characteristics. 77 | AC_C_CONST 78 | AC_C_BIGENDIAN(AC_DEFINE(BS_BIG_ENDIAN, 1, [Defined if the platform is big-endian]), 79 | AC_DEFINE(BS_LITTLE_ENDIAN, 1, [Defined if the platform is little-endian]), 80 | [ 81 | AC_MSG_RESULT(endianness unknown - will rely solely on compiler macros) 82 | AC_MSG_CHECKING([whether compiler sets endianness macros]) 83 | AC_COMPILE_IFELSE([ 84 | #if defined __LITTLE_ENDIAN__ || defined _LITTLE_ENDIAN_ || defined __BIG_ENDIAN__ || defined _BIG_ENDIAN_ 85 | #define BS_OK 1 86 | #else 87 | cannot determine compiler's endianness 88 | #endif 89 | ],[AC_MSG_RESULT(yes)],[ 90 | AC_MSG_RESULT(no) 91 | AC_MSG_ERROR([Cannot determine endianness neither from the compiler nor using a test. 92 | Try adding -D_BIG_ENDIAN_ or -D_LITTLE_ENDIAN_ to PKG_CPPFLAGS. 93 | ])]) 94 | ]) 95 | AC_HEADER_TIME 96 | 97 | # Checks for library functions. 98 | AC_FUNC_FORK 99 | AC_TYPE_SIGNAL 100 | AC_CHECK_FUNCS([memset mkdir rmdir select socket]) 101 | 102 | # Check whether we can use crypt (and if we do if it's in the crypt library) 103 | AC_SEARCH_LIBS(crypt, crypt, 104 | [AC_DEFINE(HAS_CRYPT, 1, [If defined Rserve supports unix crypt password encryption.])]) 105 | AC_CHECK_HEADERS([crypt.h]) 106 | 107 | # socket related stuff - indroduced first due to Solaris 108 | # socklen_t - note that we don't try to find an equivalent! 109 | # we'll use BSD-style int in case this one isn't defined. 110 | # that should be fine for all major platforms. 111 | AC_CHECK_TYPE(socklen_t,, 112 | AC_DEFINE(socklen_t, int, [Define to `int' if neither nor define.]), 113 | [ 114 | #include 115 | #include 116 | ]) 117 | # connect may need -lsocket and/or -lnsl (e.g. on Solaris) 118 | AC_CHECK_FUNCS(connect) 119 | if test x"$ac_cv_func_connect" = x"no"; then 120 | case "$LIBS" in 121 | *-lnsl*) ;; 122 | *) AC_CHECK_LIB(nsl_s, printf) ;; 123 | esac 124 | case "$LIBS" in 125 | *-lnsl*) ;; 126 | *) AC_CHECK_LIB(nsl, printf) ;; 127 | esac 128 | case "$LIBS" in 129 | *-lsocket*) ;; 130 | *) AC_CHECK_LIB(socket, connect) ;; 131 | esac 132 | case "$LIBS" in 133 | *-linet*) ;; 134 | *) AC_CHECK_LIB(inet, connect) ;; 135 | esac 136 | dnl We can't just call AC_CHECK_FUNCS(connect) here, because the value 137 | dnl has been cached. 138 | if test x"$ac_cv_lib_socket_connect" = x"yes" || 139 | test x"$ac_cv_lib_inet_connect" = x"yes"; then 140 | # ac_cv_func_connect=yes 141 | # don't! it would cause AC_CHECK_FUNC to succeed next time configure is run 142 | AC_DEFINE(HAVE_CONNECT, 1, [ ]) 143 | fi 144 | fi 145 | 146 | # on some platforms libR expects dl code in the binary 147 | AC_CHECK_LIB(dl, dlopen) 148 | 149 | AC_CONFIG_FILES([src/Makefile]) 150 | AC_CONFIG_FILES([src/client/cxx/Makefile]) 151 | AC_OUTPUT 152 | -------------------------------------------------------------------------------- /Rserve/configure.win: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo '--- Rserve for Windows ---' 4 | echo '' 5 | echo '** MAKE SURE YOU READ THE RSERVE RELEASE NOTES FOR WINDOWS !! **' 6 | echo '** Rserve for Windows is different in several aspects **' 7 | echo '** from the unix version, see **' 8 | echo '** http://rforge.net/Rserve/rserve-win.html **' 9 | echo '' 10 | -------------------------------------------------------------------------------- /Rserve/man/Rclient.Rd: -------------------------------------------------------------------------------- 1 | \name{Rclient} 2 | \title{Functions to talk to an Rserve} 3 | \alias{RSconnect} 4 | \alias{RSclose} 5 | \alias{RSeval} 6 | \alias{RSeval.old} 7 | \alias{RSlogin} 8 | \alias{RSdetach} 9 | \alias{RSevalDetach} 10 | \alias{RSattach} 11 | \alias{RSassign} 12 | \alias{RSassign.old} 13 | \alias{RSshutdown} 14 | \usage{ 15 | RSconnect(host = "localhost", port = 6311) 16 | RSlogin(c, user, pwd, silent = FALSE) 17 | RSeval(c, expr) 18 | RSeval.old(c, cmd) 19 | RSclose(c) 20 | RSshutdown(c, pwd = NULL) 21 | RSdetach(c) 22 | RSevalDetach(c, cmd = "") 23 | RSattach(session) 24 | RSassign(c, obj, name = deparse(substitute(obj)) ) 25 | RSassign.old(c, obj, name = deparse(substitute(obj)) ) 26 | } 27 | \description{ 28 | Rserve is a server providing R functionality via sockets. The 29 | following functions allow another R session to start new Rserve 30 | sessions and evaluate commands. The support is very rudimentary and 31 | uses only a fraction of the funtionality provided by Rserve. The 32 | typical use of Rserve is to connect to other applications, not 33 | necessarily to connect two R processes. However, it is not uncommon to 34 | have a cluster of Rserve machines so the following functions provide a 35 | simple client access. 36 | 37 | For more complete cilent implementation see \code{src/clients} 38 | directory of the Rserve distribution which show a C/C++ client. Also 39 | available from the Rserve pages is a Java client 40 | (\code{JRclient}). See \code{http://rosuda.org/Rserve} for details. 41 | } 42 | \arguments{ 43 | \item{host}{host to connect to} 44 | \item{port}{TCP port to connect to} 45 | \item{c}{Rserve connection} 46 | \item{user}{username for authentication} 47 | \item{pwd}{password for authentication} 48 | \item{cmd}{command (as string) to evaluate} 49 | \item{silent}{flag indicating whether a failure should raise an error 50 | or not} 51 | \item{session}{session object as returned by \code{RSdetach} or 52 | \code{RSevalDetach}} 53 | \item{obj}{value to assign} 54 | \item{name}{name to assign to on the remote side} 55 | \item{expr}{R expression to evaluate remotely} 56 | } 57 | \details{ 58 | \code{RSconnect} creates a connection to a Rserve. The returned handle 59 | is to be used in all subsequent calls to client functions. The session 60 | associated witht he connection is alive until closed via 61 | \code{RSclose}. 62 | 63 | \code{RSlogin} performs authentication with the Rserve. Currently this 64 | simple client supports only plain text authentication, encryption is 65 | not supported. 66 | 67 | \code{RSclose} closes the Rserve connection. 68 | 69 | \code{RSeval} evaluates the supplied expression 70 | remotely. \code{expr} can be either a string or any R 71 | expression. Use \code{\link{quote}} to use unevaluated 72 | expressions. The implementation of \code{RSeval} is very efficient 73 | in that it does not require any buffer on the remote side and uses 74 | native R serialization as the protocol. See exmples below for 75 | correct use. 76 | 77 | \code{RSeval.old} is deprecated and present only for compatibility 78 | with older Rserve implementations. It evaluates the string in the 79 | remote Rserve and returns 80 | the result. Note that you will have to load the same packages on both 81 | ends if the result is an (S3/S4) object such that corresponding 82 | classes and methods are available. Also note that the result is 83 | transported on the network so sending huge results can be slow. Thus 84 | consider sending only relebant parts or keep the results on the other 85 | end if pertinent. 86 | 87 | \code{RSdetach} detaches from the current Rserve connection. The 88 | connection is closed but can be restored by using \code{RSattach} with 89 | the value returned by \code{RSdetach}. Technically the R on the other 90 | end is still running and waiting to be atached. 91 | 92 | \code{RSshutdown} terminates the server gracefully. It should be 93 | immediately followed by \code{RSclose} since the server closes the 94 | connection. It can be issued only on a valid (authenticated) 95 | connection. The password parameter is currently ignored since 96 | password-protected shutdown is not yet supported. Please note that 97 | you should not terminate servers that you did not start. 98 | 99 | \code{RSevalDetach} same as \code{RSdetach} but allows asynchronous 100 | evaluation of the command. The remote Rserve is instructed to evaluate 101 | the command after the connection is detached. Please note that the 102 | session cannot be attached until the evaluation finished. Therefore it 103 | is advisable to use another session when attaching to verify the 104 | status of the detached session where necessary. 105 | 106 | \code{RSattach} resume connection to an existing session in 107 | Rserve. The \code{session} argument must have been previously returned 108 | from the \code{RSdetach} or \code{RSevalDetach} comment. 109 | 110 | \code{RSassign} pushes an object to Rserve and assigns it to the given 111 | name. Note that the name can be an (unevaluated) R expression itself 112 | thus allowing constructs such as \code{RSassign(c, 1:5, 113 | quote(a$foo))} which will result in \code{a$foo <- 1:5} 114 | remotely. However, character names are interpreted literarly. 115 | } 116 | \examples{ 117 | \dontrun{ 118 | c <- RSconnect() 119 | data(stackloss) 120 | RSassign(c, stackloss) 121 | RSeval(c, quote(library(MASS))) 122 | RSeval(c, quote(rlm(stack.loss ~ ., stackloss)$coeff)) 123 | RSeval(c, "getwd()") 124 | 125 | image <- RSeval(c, quote(try({ 126 | attach(stackloss) 127 | library(Cairo) 128 | Cairo(file="plot.png") 129 | plot(Air.Flow,stack.loss,col=2,pch=19,cex=2) 130 | dev.off() 131 | readBin("plot.png", "raw", 999999)}))) 132 | if (inherits(image, "try-error")) 133 | stop(image) 134 | } 135 | } 136 | \author{Simon Urbanek} 137 | \keyword{interface} 138 | -------------------------------------------------------------------------------- /Rserve/man/Rserv.Rd: -------------------------------------------------------------------------------- 1 | \name{Rserve} 2 | \title{Server providing R functionality to applications via TCP/IP or local unix sockets} 3 | \alias{Rserve} 4 | \usage{ 5 | # R CMD Rserve [] 6 | 7 | Rserve(debug = FALSE, port = 6311, args = NULL) 8 | } 9 | \synopsis{ 10 | Rserve(debug = FALSE, port = 6311, args = NULL) 11 | } 12 | \description{ 13 | Starts Rserve in daemon mode (unix only). Any additional parameters 14 | not related to Rserve will be passed straight to the underlying R. For 15 | configuration, usage and command line parameters please consult the 16 | online documentation at http://www.rosuda.org/Rserve. Use \code{R CMD Rserve 17 | --help} for a brief help. 18 | 19 | The \code{Rserve} function is provided for convenience only, it is 20 | recommended to start Rserve directly from the command line, not from R 21 | itself. Also note that the debug version of Rserve doesn't fork and thus 22 | will block until closed. 23 | } 24 | \arguments{ 25 | \item{debug}{determines whether regular Rserve or debug version of 26 | Rserve (\code{Rserve.dbg}) should be started.} 27 | \item{port}{port used by Rserve to listen for connections} 28 | \item{args}{further arguments passed to Rserve (as a string that will be 29 | passed to the \code{system} command thus use quotes where necessary).} 30 | } 31 | \details{ 32 | Rserve is not just a package, but an application. It is provided as a 33 | R package for convenience only. For details see 34 | http://www.rosuda.org/Rserve 35 | } 36 | \author{Simon Urbanek} 37 | \keyword{interface} 38 | -------------------------------------------------------------------------------- /Rserve/src/Makefile.in: -------------------------------------------------------------------------------- 1 | XFILES = Rserve Rserve.dbg 2 | 3 | # modify these variables to match your setup 4 | Rhome = @R_LIBS@ 5 | port = . 6 | LIBS = @LIBS@ 7 | 8 | # if you have some non-standard setup you might want to modify those as well 9 | Rincludes = @RINC@ 10 | Rlib = $(R_LIBS)/lib 11 | Rbin = $(R_LIBS)/bin 12 | linkR = @RLD@ 13 | 14 | MYINC = -Iinclude -I$(port) 15 | PKG_CFLAGS += -DDAEMON $(MYINC) $(Rincludes) 16 | 17 | all: Rserve$(SHLIB_EXT) @WITH_SERVER_TRUE@ server 18 | @WITH_CLIENT_TRUE@ $(MAKE) client 19 | 20 | server: $(XFILES) 21 | # when installing multiple archs we have no way to put the binaries in the correct directory 22 | # because only *.so get copied. Therefore we need to fake the bin files as ".so"s to get 23 | # copied. Not a nice hack, but it works... 24 | -cp Rserve Rserve-bin$(SHLIB_EXT) 25 | -cp Rserve.dbg Rserve-dbg$(SHLIB_EXT) 26 | # merging to bin/Rserve works only if installed from sources, won't work for binary 27 | -./mergefat Rserve "$(Rbin)/Rserve" 28 | -./mergefat Rserve.dbg "$(Rbin)/Rserve.dbg" 29 | # installing the bin files is disabled for now because additional archs won't work anyway 30 | # -cp $(XFILES) $(Rbin) 31 | # -mkdir -p ../inst/bin$(R_ARCH) 2>/dev/null 32 | # -cp $(XFILES) ../inst/bin$(R_ARCH)/ 33 | 34 | # we copy the binary only in single-arch case to avoid confusion 35 | -@mkdir -p ../inst 2>/dev/null 36 | -@if test "x$(R_ARCH)" = x; then cp $(XFILES) ../inst/; else echo "Rserve binary was installed in libs because multi-arch support is enabled." > ../inst/Rserve-bin.txt; fi 37 | 38 | install: @WITH_SERVER_TRUE@ $(XFILES) 39 | @WITH_SERVER_TRUE@ -cp Rserve $(Rbin)/Rserve 40 | @WITH_SERVER_TRUE@ -cp Rserve.dbg $(Rbin)/Rserve.dbg 41 | 42 | Rserv.o: Rserv.c Rsrv.h 43 | $(CC) $(MYINC) $(Rincludes) -c Rserv.c -o $@ -DNDEBUG -DDAEMON -fstack-protector $(PKG_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) 44 | 45 | session.o: session.o 46 | $(CC) $(MYINC) $(Rincludes) -c session.c -o $@ -DNDEBUG -DDAEMON -fstack-protector $(PKG_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) 47 | 48 | md5.o: md5.c 49 | $(CC) $(MYINC) $(Rincludes) -c md5.c -o $@ -DNDEBUG -DDAEMON -fstack-protector $(PKG_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) 50 | 51 | Rserve: Rserv.o session.o md5.o 52 | $(CC) $^ -o $@ $(linkR) $(LIBS) $(PKG_LIBS) -lpthread 53 | 54 | Rserv_d.o: Rserv.c Rsrv.h 55 | $(CC) $(MYINC) $(Rincludes) -c Rserv.c -o $@ -DNODAEMON -DRSERV_DEBUG -g -fstack-protector $(PKG_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) 56 | 57 | Rserve.dbg: Rserv_d.o session.o md5.o 58 | $(CC) $^ -o $@ $(linkR) $(LIBS) $(PKG_LIBS) -lpthread 59 | 60 | # this is fake for now - we should switch to Makevars.in and compile a proper library 61 | Rserve$(SHLIB_EXT): @WITH_SERVER_TRUE@ Rserve 62 | @WITH_SERVER_TRUE@ cp $^ $@ 63 | @WITH_SERVER_FALSE@ -@( touch $@; mkdir ../inst 2>/dev/null; echo "Server was not compiled." > ../inst/Rserve.txt ) 64 | 65 | client: config.h 66 | cp config.h client/cxx/ 67 | make -C client/cxx 68 | -@mkdir ../inst 2>/dev/null 69 | -rm -rf ../inst/client 70 | -cp -r client ../inst/ 71 | cp Rsrv.h config.h include/sisocks.h ../inst/client/cxx/ 72 | 73 | clean: 74 | rm -f *~ *.o *.lo *.so \#* $(XFILES) 75 | 76 | .PHONY: client clean server install 77 | -------------------------------------------------------------------------------- /Rserve/src/Makefile.win: -------------------------------------------------------------------------------- 1 | include $(R_HOME)/etc$(R_ARCH)/Makeconf 2 | 3 | all: $(SHLIB) instdir Rserve.exe Rserve_d.exe 4 | 5 | .PHONY: all instdir 6 | 7 | INSTDIR = ../inst 8 | 9 | MAIN_LD = $(CC) 10 | PKG_CPPFLAGS = -DWin32 -I. -D_R_ -Iinst/include -Iinclude -Iinclude/Win32 11 | R_BIN=$(R_HOME)/bin$(R_ARCH) 12 | ARCH=`echo $(R_ARCH) | sed 's:/:_:g'` 13 | 14 | Rserv_d.o: Rserv.c 15 | $(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) -DRSERV_DEBUG -g -c $< -o $@ 16 | 17 | instdir: 18 | -@mkdir $(INSTDIR) 2>/dev/null 19 | -@mkdir -p $(INSTDIR)/libs$(R_ARCH) 2>/dev/null 20 | 21 | Rserve.exe: Rserv.o winembed.o 22 | $(LINKER) -s -o $@ $^ -lws2_32 -L$(R_BIN) -lR 23 | -cp $@ $(INSTDIR)/Rserve.exe 24 | -cp $@ $(INSTDIR)/Rserve$(ARCH).exe 25 | -cp $@ "$(R_BIN)" 26 | -cp $@ $(INSTDIR)/libs$(R_ARCH) 27 | 28 | Rserve_d.exe: Rserv_d.o winembed.o 29 | $(LINKER) -o $@ $^ -lws2_32 -L$(R_BIN) -lR 30 | -cp $@ $(INSTDIR)/Rserve_d.exe 31 | -cp $@ $(INSTDIR)/Rserve_d$(ARCH).exe 32 | -cp $@ "$(R_BIN)" 33 | -cp $@ $(INSTDIR)/libs$(R_ARCH) 34 | 35 | clean: 36 | -rm -f *.o Rserve.exe Rserve_d.exe 37 | 38 | distclean: clean 39 | -rm -rf $(INSTDIR) 40 | -------------------------------------------------------------------------------- /Rserve/src/client/README.txt: -------------------------------------------------------------------------------- 1 | This directory contains various Rserve clients: 2 | 3 | cxx - minimal C++ client 4 | 5 | java-new - Java client based on the REngine API. This is the actively 6 | developed Java client as it is more flexible and 7 | consistent than the older JRclient. It supports multiple 8 | back-ends such as Rserve or JRI. 9 | 10 | java-old - old Java client (JRclient). This was the first 11 | implementation of a Java cilent, but has been now replaced 12 | by the REngine API. It is still maitained for 13 | compatibility with older programs, but it will be phased 14 | out eventually. 15 | 16 | -------------------------------------------------------------------------------- /Rserve/src/client/cxx/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for C++ Rserve clients. 2 | # 3 | # $Id: Makefile.in 213 2008-01-10 22:46:01Z urbanek $ 4 | 5 | SRC = $(wildcard *.cc) 6 | OBJ = $(SRC:%.cc=%.o) 7 | DST = demo1 rcons rsdown 8 | 9 | LIBS+=-ldl -lcrypt 10 | CPPFLAGS+=-DHAVE_CONFIG_H 11 | 12 | all: $(DST) $(OBJ) 13 | 14 | %: Rconnection.o %.o 15 | $(CXX) $^ -o $@ $(LIBS) 16 | 17 | debug: 18 | $(MAKE) CXXFLAGS=-g all 19 | 20 | clean: 21 | rm -rf *~ *.o \#* .\#* $(DST) 22 | -------------------------------------------------------------------------------- /Rserve/src/client/cxx/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile for C++ Rserve clients. 2 | # 3 | # $Id: Makefile.in 213 2008-01-10 22:46:01Z urbanek $ 4 | 5 | SRC = $(wildcard *.cc) 6 | OBJ = $(SRC:%.cc=%.o) 7 | DST = demo1 rcons rsdown 8 | 9 | LIBS+=@LIBS@ 10 | CPPFLAGS+=-DHAVE_CONFIG_H 11 | 12 | all: $(DST) $(OBJ) 13 | 14 | %: Rconnection.o %.o 15 | $(CXX) $^ -o $@ $(LIBS) 16 | 17 | debug: 18 | $(MAKE) CXXFLAGS=-g all 19 | 20 | clean: 21 | rm -rf *~ *.o \#* .\#* $(DST) 22 | -------------------------------------------------------------------------------- /Rserve/src/client/cxx/Makefile.win: -------------------------------------------------------------------------------- 1 | # Makefile for C++ Rserve clients - Win32 version 2 | # 3 | # $Id: Makefile.win 203 2007-05-10 18:12:06Z urbanek $ 4 | 5 | SRC = $(wildcard *.cc) 6 | OBJ = $(SRC:%.cc=%.o) 7 | DST = demo1 rcons 8 | 9 | CXXFLAGS+=-I../include -I../include/Win32 -I.. -I. -DWin32 10 | LIBS+=-lwsock32 11 | linkRL= 12 | 13 | all: $(DST) 14 | 15 | demo1: Rconnection.o demo1.o 16 | $(CXX) $^ -o $@ $(LIBS) 17 | 18 | rcons: Rconnection.o rcons.o 19 | $(CXX) $^ -o $@ $(LIBS) $(linkRL) 20 | 21 | debug: 22 | CXXFLAGS=-g $(MAKE) all 23 | 24 | clean: 25 | rm -rf *~ *.o \#* .\#* $(DST) 26 | -------------------------------------------------------------------------------- /Rserve/src/client/cxx/ReadMe.txt: -------------------------------------------------------------------------------- 1 | This directory contains a sample C++ client for Rserve 2 | 3 | You can compile this client without R. Just run "configure" in the 4 | Rserve directory, a corresponding Makefile will be automatically 5 | generated. 6 | Win32: There is no configure for Windows, but there is a special 7 | Makefile.win to build it - use "make -f Makefile.win" - it requires 8 | MinGW (or compatible) and GNU make. 9 | 10 | This C++ interface is experimental and does not come in form of a 11 | library, it is left to the user to build one or just use it in static 12 | form. Rconnection.h and Rconnection.cc is all that's needed. This 13 | directory also contains two little examples: 14 | 15 | * demo1.cc 16 | This (rather silly) example demonstrates the basic use of the 17 | API, such as assigning contents, evaluating expressions and fetching 18 | various parts of the data. 19 | 20 | * rcons.cc 21 | A very simple console to Rserve. It uses the os_print method to print 22 | the results and its attributes. It is helpful if you want to 23 | understand how R and Rserve stores various expressions. 24 | 25 | * rcmd.cc 26 | This program "sources" all files specified on the command line into 27 | a Rserve session and prints its output. It is something like a 'fast' 28 | version of R CMD BATCH. It's very simple, so look at the code if 29 | you want a more sophisticated behavior. 30 | 31 | The entire C++ interface handles only the most basic types such as 32 | lists, vectors, doubles, integers and strings. Look at the sources 33 | to see how to implement other types if necessary (although there 34 | isn't too much missing, maybe logical vectors ...). 35 | 36 | A word about the memory allocation of the objects here: in most cases 37 | the memory is allocated by the Rmessage object that receives the 38 | evaluated expression for R. All further Rexp objects are just 39 | pointers inside that message. For convenience there is one "main" 40 | Rexp, which knows about the message and automaically deallocates it 41 | upon its own destruction. This means that from user's point of view 42 | there is always only *one* object which can be deleted, namely the 43 | one returned by 'eval'. The user should *never* delete any object 44 | obtained indirectly from another Rexp. Complex Rexps, such as Rvector 45 | always return direct pointers to their content. This applies also to 46 | pointer to other types obtained from Rexp such as doubleArray of 47 | Rdouble. You should always copy this content if you plan to make 48 | modifications. This approach was taken to provide very fast access to 49 | all objects returned from Rserve. Usually noting needs to be copied 50 | - this is imporant, because the objects could be quite large. 51 | 52 | Please feel free to contribute to this project. I don't use this C++ 53 | interface myself, therefore it is left to the users to extend it 54 | further. All low-level handling is implemented, therefore it is much 55 | easier to add high-level functionality. 56 | 57 | see also: http://www.rosuda.org/Rserve/ 58 | 59 | Simon Urbanek, Sept 2004 60 | -------------------------------------------------------------------------------- /Rserve/src/client/cxx/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define if building universal (internal helper macro) */ 5 | /* #undef AC_APPLE_UNIVERSAL_BUILD */ 6 | 7 | /* Defined if the platform is big-endian */ 8 | /* #undef BS_BIG_ENDIAN */ 9 | 10 | /* Defined if the platform is little-endian */ 11 | #define BS_LITTLE_ENDIAN 1 12 | 13 | /* If defined Rserve supports unix crypt password encryption. */ 14 | #define HAS_CRYPT 1 15 | 16 | /* */ 17 | #define HAVE_CONNECT 1 18 | 19 | /* Define to 1 if you have the header file. */ 20 | #define HAVE_CRYPT_H 1 21 | 22 | /* Define to 1 if you have the `fork' function. */ 23 | #define HAVE_FORK 1 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_INTTYPES_H 1 27 | 28 | /* Define to 1 if you have the `dl' library (-ldl). */ 29 | #define HAVE_LIBDL 1 30 | 31 | /* Define to 1 if you have the `inet' library (-linet). */ 32 | /* #undef HAVE_LIBINET */ 33 | 34 | /* Define to 1 if you have the `nsl' library (-lnsl). */ 35 | /* #undef HAVE_LIBNSL */ 36 | 37 | /* Define to 1 if you have the `nsl_s' library (-lnsl_s). */ 38 | /* #undef HAVE_LIBNSL_S */ 39 | 40 | /* Define to 1 if you have the `socket' library (-lsocket). */ 41 | /* #undef HAVE_LIBSOCKET */ 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_MEMORY_H 1 45 | 46 | /* Define to 1 if you have the `memset' function. */ 47 | #define HAVE_MEMSET 1 48 | 49 | /* Define to 1 if you have the `mkdir' function. */ 50 | #define HAVE_MKDIR 1 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #define HAVE_NETINET_IN_H 1 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #define HAVE_NETINET_TCP_H 1 57 | 58 | /* Define to 1 if you have the `rmdir' function. */ 59 | #define HAVE_RMDIR 1 60 | 61 | /* Define to 1 if you have the `select' function. */ 62 | #define HAVE_SELECT 1 63 | 64 | /* Define to 1 if you have the `socket' function. */ 65 | #define HAVE_SOCKET 1 66 | 67 | /* Define to 1 if you have the header file. */ 68 | #define HAVE_STDINT_H 1 69 | 70 | /* Define to 1 if you have the header file. */ 71 | #define HAVE_STDLIB_H 1 72 | 73 | /* Define to 1 if you have the header file. */ 74 | #define HAVE_STRINGS_H 1 75 | 76 | /* Define to 1 if you have the header file. */ 77 | #define HAVE_STRING_H 1 78 | 79 | /* Define to 1 if you have the header file. */ 80 | #define HAVE_SYS_SOCKET_H 1 81 | 82 | /* Define to 1 if you have the header file. */ 83 | #define HAVE_SYS_STAT_H 1 84 | 85 | /* Define to 1 if you have the header file. */ 86 | #define HAVE_SYS_TIME_H 1 87 | 88 | /* Define to 1 if you have the header file. */ 89 | #define HAVE_SYS_TYPES_H 1 90 | 91 | /* Define to 1 if you have the header file. */ 92 | #define HAVE_SYS_UN_H 1 93 | 94 | /* Define to 1 if you have that is POSIX.1 compatible. */ 95 | #define HAVE_SYS_WAIT_H 1 96 | 97 | /* Define to 1 if you have the header file. */ 98 | #define HAVE_UNISTD_H 1 99 | 100 | /* Define to 1 if you have the `vfork' function. */ 101 | #define HAVE_VFORK 1 102 | 103 | /* Define to 1 if you have the header file. */ 104 | /* #undef HAVE_VFORK_H */ 105 | 106 | /* Define to 1 if `fork' works. */ 107 | #define HAVE_WORKING_FORK 1 108 | 109 | /* Define to 1 if `vfork' works. */ 110 | #define HAVE_WORKING_VFORK 1 111 | 112 | /* Define to the address where bug reports for this package should be sent. */ 113 | #define PACKAGE_BUGREPORT "Simon.Urbanek@r-project.org" 114 | 115 | /* Define to the full name of this package. */ 116 | #define PACKAGE_NAME "Rserve-cxx-client" 117 | 118 | /* Define to the full name and version of this package. */ 119 | #define PACKAGE_STRING "Rserve-cxx-client 0.1" 120 | 121 | /* Define to the one symbol short name of this package. */ 122 | #define PACKAGE_TARNAME "rserve-cxx-client" 123 | 124 | /* Define to the home page for this package. */ 125 | #define PACKAGE_URL "" 126 | 127 | /* Define to the version of this package. */ 128 | #define PACKAGE_VERSION "0.1" 129 | 130 | /* Define as the return type of signal handlers (`int' or `void'). */ 131 | #define RETSIGTYPE void 132 | 133 | /* Define to 1 if you have the ANSI C header files. */ 134 | #define STDC_HEADERS 1 135 | 136 | /* Define to 1 if you can safely include both and . */ 137 | #define TIME_WITH_SYS_TIME 1 138 | 139 | /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most 140 | significant byte first (like Motorola and SPARC, unlike Intel). */ 141 | #if defined AC_APPLE_UNIVERSAL_BUILD 142 | # if defined __BIG_ENDIAN__ 143 | # define WORDS_BIGENDIAN 1 144 | # endif 145 | #else 146 | # ifndef WORDS_BIGENDIAN 147 | /* # undef WORDS_BIGENDIAN */ 148 | # endif 149 | #endif 150 | 151 | /* Define to empty if `const' does not conform to ANSI C. */ 152 | /* #undef const */ 153 | 154 | /* Define to `int' if does not define. */ 155 | /* #undef pid_t */ 156 | 157 | /* Define to `int' if neither nor define. */ 158 | /* #undef socklen_t */ 159 | 160 | /* Define as `fork' if `vfork' does not work. */ 161 | /* #undef vfork */ 162 | -------------------------------------------------------------------------------- /Rserve/src/client/cxx/config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define if building universal (internal helper macro) */ 4 | #undef AC_APPLE_UNIVERSAL_BUILD 5 | 6 | /* Defined if the platform is big-endian */ 7 | #undef BS_BIG_ENDIAN 8 | 9 | /* Defined if the platform is little-endian */ 10 | #undef BS_LITTLE_ENDIAN 11 | 12 | /* If defined Rserve supports unix crypt password encryption. */ 13 | #undef HAS_CRYPT 14 | 15 | /* */ 16 | #undef HAVE_CONNECT 17 | 18 | /* Define to 1 if you have the header file. */ 19 | #undef HAVE_CRYPT_H 20 | 21 | /* Define to 1 if you have the `fork' function. */ 22 | #undef HAVE_FORK 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_INTTYPES_H 26 | 27 | /* Define to 1 if you have the `dl' library (-ldl). */ 28 | #undef HAVE_LIBDL 29 | 30 | /* Define to 1 if you have the `inet' library (-linet). */ 31 | #undef HAVE_LIBINET 32 | 33 | /* Define to 1 if you have the `nsl' library (-lnsl). */ 34 | #undef HAVE_LIBNSL 35 | 36 | /* Define to 1 if you have the `nsl_s' library (-lnsl_s). */ 37 | #undef HAVE_LIBNSL_S 38 | 39 | /* Define to 1 if you have the `socket' library (-lsocket). */ 40 | #undef HAVE_LIBSOCKET 41 | 42 | /* Define to 1 if you have the header file. */ 43 | #undef HAVE_MEMORY_H 44 | 45 | /* Define to 1 if you have the `memset' function. */ 46 | #undef HAVE_MEMSET 47 | 48 | /* Define to 1 if you have the `mkdir' function. */ 49 | #undef HAVE_MKDIR 50 | 51 | /* Define to 1 if you have the header file. */ 52 | #undef HAVE_NETINET_IN_H 53 | 54 | /* Define to 1 if you have the header file. */ 55 | #undef HAVE_NETINET_TCP_H 56 | 57 | /* Define to 1 if you have the `rmdir' function. */ 58 | #undef HAVE_RMDIR 59 | 60 | /* Define to 1 if you have the `select' function. */ 61 | #undef HAVE_SELECT 62 | 63 | /* Define to 1 if you have the `socket' function. */ 64 | #undef HAVE_SOCKET 65 | 66 | /* Define to 1 if you have the header file. */ 67 | #undef HAVE_STDINT_H 68 | 69 | /* Define to 1 if you have the header file. */ 70 | #undef HAVE_STDLIB_H 71 | 72 | /* Define to 1 if you have the header file. */ 73 | #undef HAVE_STRINGS_H 74 | 75 | /* Define to 1 if you have the header file. */ 76 | #undef HAVE_STRING_H 77 | 78 | /* Define to 1 if you have the header file. */ 79 | #undef HAVE_SYS_SOCKET_H 80 | 81 | /* Define to 1 if you have the header file. */ 82 | #undef HAVE_SYS_STAT_H 83 | 84 | /* Define to 1 if you have the header file. */ 85 | #undef HAVE_SYS_TIME_H 86 | 87 | /* Define to 1 if you have the header file. */ 88 | #undef HAVE_SYS_TYPES_H 89 | 90 | /* Define to 1 if you have the header file. */ 91 | #undef HAVE_SYS_UN_H 92 | 93 | /* Define to 1 if you have that is POSIX.1 compatible. */ 94 | #undef HAVE_SYS_WAIT_H 95 | 96 | /* Define to 1 if you have the header file. */ 97 | #undef HAVE_UNISTD_H 98 | 99 | /* Define to 1 if you have the `vfork' function. */ 100 | #undef HAVE_VFORK 101 | 102 | /* Define to 1 if you have the header file. */ 103 | #undef HAVE_VFORK_H 104 | 105 | /* Define to 1 if `fork' works. */ 106 | #undef HAVE_WORKING_FORK 107 | 108 | /* Define to 1 if `vfork' works. */ 109 | #undef HAVE_WORKING_VFORK 110 | 111 | /* Define to the address where bug reports for this package should be sent. */ 112 | #undef PACKAGE_BUGREPORT 113 | 114 | /* Define to the full name of this package. */ 115 | #undef PACKAGE_NAME 116 | 117 | /* Define to the full name and version of this package. */ 118 | #undef PACKAGE_STRING 119 | 120 | /* Define to the one symbol short name of this package. */ 121 | #undef PACKAGE_TARNAME 122 | 123 | /* Define to the home page for this package. */ 124 | #undef PACKAGE_URL 125 | 126 | /* Define to the version of this package. */ 127 | #undef PACKAGE_VERSION 128 | 129 | /* Define as the return type of signal handlers (`int' or `void'). */ 130 | #undef RETSIGTYPE 131 | 132 | /* Define to 1 if you have the ANSI C header files. */ 133 | #undef STDC_HEADERS 134 | 135 | /* Define to 1 if you can safely include both and . */ 136 | #undef TIME_WITH_SYS_TIME 137 | 138 | /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most 139 | significant byte first (like Motorola and SPARC, unlike Intel). */ 140 | #if defined AC_APPLE_UNIVERSAL_BUILD 141 | # if defined __BIG_ENDIAN__ 142 | # define WORDS_BIGENDIAN 1 143 | # endif 144 | #else 145 | # ifndef WORDS_BIGENDIAN 146 | # undef WORDS_BIGENDIAN 147 | # endif 148 | #endif 149 | 150 | /* Define to empty if `const' does not conform to ANSI C. */ 151 | #undef const 152 | 153 | /* Define to `int' if does not define. */ 154 | #undef pid_t 155 | 156 | /* Define to `int' if neither nor define. */ 157 | #undef socklen_t 158 | 159 | /* Define as `fork' if `vfork' does not work. */ 160 | #undef vfork 161 | -------------------------------------------------------------------------------- /Rserve/src/client/cxx/configure.ac: -------------------------------------------------------------------------------- 1 | # Process this file with autoconf to produce a configure script. 2 | AC_INIT([Rserve-cxx-client],[0.1],[Simon.Urbanek@r-project.org]) 3 | AC_CONFIG_SRCDIR([Rconnection.cc]) 4 | AC_CONFIG_HEADER([config.h]) 5 | 6 | AC_PROG_CC 7 | AC_PROG_CXX 8 | AC_HEADER_STDC 9 | AC_HEADER_SYS_WAIT 10 | AC_CHECK_HEADERS([string.h memory.h sys/time.h unistd.h]) 11 | AC_CHECK_HEADERS([sys/stat.h sys/types.h sys/socket.h sys/un.h netinet/in.h netinet/tcp.h]) 12 | 13 | # Checks for typedefs, structures, and compiler characteristics. 14 | AC_C_CONST 15 | AC_C_BIGENDIAN(AC_DEFINE(BS_BIG_ENDIAN, 1, [Defined if the platform is big-endian]), 16 | AC_DEFINE(BS_LITTLE_ENDIAN, 1, [Defined if the platform is little-endian]), 17 | [ 18 | AC_MSG_RESULT(endianness unknown - will rely solely on compiler macros) 19 | AC_MSG_CHECKING([whether compiler sets endianness macros]) 20 | AC_COMPILE_IFELSE([ 21 | #if defined __LITTLE_ENDIAN__ || defined _LITTLE_ENDIAN_ || defined __BIG_ENDIAN__ || defined _BIG_ENDIAN_ 22 | #define BS_OK 1 23 | #else 24 | cannot determine compiler's endianness 25 | #endif 26 | ],[AC_MSG_RESULT(yes)],[ 27 | AC_MSG_RESULT(no) 28 | AC_MSG_ERROR([Cannot determine endianness neither from the compiler nor using a test. 29 | Try adding -D_BIG_ENDIAN_ or -D_LITTLE_ENDIAN_ to PKG_CPPFLAGS. 30 | ])]) 31 | ]) 32 | AC_HEADER_TIME 33 | 34 | # Checks for library functions. 35 | AC_FUNC_FORK 36 | AC_TYPE_SIGNAL 37 | AC_CHECK_FUNCS([memset mkdir rmdir select socket]) 38 | 39 | # Check whether we can use crypt (and if we do if it's in the crypt library) 40 | AC_SEARCH_LIBS(crypt, crypt, 41 | [AC_DEFINE(HAS_CRYPT, 1, [If defined Rserve supports unix crypt password encryption.])]) 42 | AC_CHECK_HEADERS([crypt.h]) 43 | 44 | # socket related stuff - indroduced first due to Solaris 45 | # socklen_t - note that we don't try to find an equivalent! 46 | # we'll use BSD-style int in case this one isn't defined. 47 | # that should be fine for all major platforms. 48 | AC_CHECK_TYPE(socklen_t,, 49 | AC_DEFINE(socklen_t, int, [Define to `int' if neither nor define.]), 50 | [ 51 | #include 52 | #include 53 | ]) 54 | # connect may need -lsocket and/or -lnsl (e.g. on Solaris) 55 | AC_CHECK_FUNCS(connect) 56 | if test x"$ac_cv_func_connect" = x"no"; then 57 | case "$LIBS" in 58 | *-lnsl*) ;; 59 | *) AC_CHECK_LIB(nsl_s, printf) ;; 60 | esac 61 | case "$LIBS" in 62 | *-lnsl*) ;; 63 | *) AC_CHECK_LIB(nsl, printf) ;; 64 | esac 65 | case "$LIBS" in 66 | *-lsocket*) ;; 67 | *) AC_CHECK_LIB(socket, connect) ;; 68 | esac 69 | case "$LIBS" in 70 | *-linet*) ;; 71 | *) AC_CHECK_LIB(inet, connect) ;; 72 | esac 73 | dnl We can't just call AC_CHECK_FUNCS(connect) here, because the value 74 | dnl has been cached. 75 | if test x"$ac_cv_lib_socket_connect" = x"yes" || 76 | test x"$ac_cv_lib_inet_connect" = x"yes"; then 77 | # ac_cv_func_connect=yes 78 | # don't! it would cause AC_CHECK_FUNC to succeed next time configure is run 79 | AC_DEFINE(HAVE_CONNECT, 1, [ ]) 80 | fi 81 | fi 82 | 83 | # on some platforms libR expects dl code in the binary 84 | AC_CHECK_LIB(dl, dlopen) 85 | 86 | AC_CONFIG_FILES([Makefile]) 87 | AC_OUTPUT 88 | -------------------------------------------------------------------------------- /Rserve/src/client/cxx/demo1.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Small demo to illustrate the use of the C++ interface to Rserve 3 | * Copyright (C) 2004 Simon Urbanek, All rights reserved. 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation; version 2.1 of the License 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Leser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | * 18 | * $Id: demo1.cc 258 2009-01-25 18:01:51Z urbanek $ 19 | */ 20 | 21 | #include 22 | using std::cout; 23 | 24 | #define MAIN // we are the main program, we need to define this 25 | #define SOCK_ERRORS // we will use verbose socket errors 26 | 27 | #include "sisocks.h" 28 | #include "Rconnection.h" 29 | 30 | // this is just a very silly example to show how the C++ API works ... 31 | 32 | int main(int argc, char **argv) { 33 | initsocks(); // this is needed for Win32 - it does nothing on unix 34 | 35 | Rconnection *rc = new Rconnection(); 36 | 37 | int i=rc->connect(); 38 | if (i) { 39 | char msg[128]; 40 | sockerrorchecks(msg, 128, -1); 41 | printf("unable to connect (result=%d, socket:%s).\n", i, msg); return i; 42 | } 43 | 44 | double d[6] = { 1.5, 2.4, 5.6, -1.2, 0.6, 1.7 }; 45 | 46 | // assign the above contents to the variable "a" in R 47 | Rdouble *rd = new Rdouble(d, 6); 48 | rc->assign("a", rd); 49 | delete rd; 50 | 51 | // create a 2 x 3 matrix named "b" and calculate b * t(b) matrix product 52 | Rdouble *x = (Rdouble*) rc->eval("b<-matrix(a,2); b%*%t(b)"); 53 | 54 | if (x) { // if everything was fine, we have the result 55 | cout << x << "\n"; 56 | 57 | // just for fun - let's get the matrix dimensionality 58 | Rinteger *dim = (Rinteger*) x->attribute("dim"); 59 | if (dim) 60 | cout << dim->intAt(0) << " by " << dim->intAt(1) << " matrix\n"; 61 | 62 | // and print the contents of the matrix (unformatted) 63 | double *d = x->doubleArray(); 64 | int i=0, ct = x->length(); 65 | while (i < ct) { cout << d[i++] << " "; } 66 | cout << "\n"; 67 | 68 | // finally dispose of the object 69 | delete x; 70 | } 71 | 72 | // integer constant assignment test 73 | int ia[6] = { 1, 4, 6, 3, 5 , 2 }; 74 | Rinteger *ri = new Rinteger(ia, 6); 75 | rc->assign("i", ri); 76 | delete ri; 77 | 78 | // let's get the whole iris data 79 | Rvector *iris = (Rvector*) rc->eval("data(iris); iris"); 80 | if (!iris) { cout << "oops! couldn't get iris data\n"; delete rc; return 0; } 81 | 82 | // now let's just get the sepal width - this a cheap operation, no talking to Rserve, because we have all the data already 83 | Rdouble *sw = (Rdouble*) iris->byName("Sepal.Width"); 84 | double *swd = sw->doubleArray(); 85 | 86 | // and print it ... 87 | { int i=0, ct=sw->length(); while (i 22 | using std::cout; 23 | 24 | #define MAIN // we are the main program, we need to define this 25 | #define SOCK_ERRORS // we will use verbose socket errors 26 | 27 | #include "sisocks.h" 28 | #include "Rconnection.h" 29 | 30 | // this is just a very silly example to show how the C++ API works ... 31 | 32 | int main(int argc, char **argv) { 33 | initsocks(); // this is needed for Win32 - it does nothing on unix 34 | 35 | Rconnection *rc = new Rconnection(); 36 | 37 | int i=rc->connect(); 38 | if (i) { 39 | char msg[128]; 40 | sockerrorchecks(msg, 128, -1); 41 | printf("unable to connect (result=%d, socket:%s).\n", i, msg); return i; 42 | } 43 | 44 | double d[6] = { 1.5, 2.4, 5.6, -1.2, 0.6, 1.7 }; 45 | 46 | // assign the above contents to the variable "a" in R 47 | Rdouble *rd = new Rdouble(d, 6); 48 | rc->assign("a", rd); 49 | delete rd; 50 | 51 | // create a 2 x 3 matrix named "b" and calculate b * t(b) matrix product 52 | Rdouble *x = (Rdouble*) rc->eval("b<-matrix(a,2); b%*%t(b)"); 53 | 54 | if (x) { // if everything was fine, we have the result 55 | cout << x << "\n"; 56 | 57 | // just for fun - let's get the matrix dimensionality 58 | Rinteger *dim = (Rinteger*) x->attribute("dim"); 59 | if (dim) 60 | cout << dim->intAt(0) << " by " << dim->intAt(1) << " matrix\n"; 61 | 62 | // and print the contents of the matrix (unformatted) 63 | double *d = x->doubleArray(); 64 | int i=0, ct = x->length(); 65 | while (i < ct) { cout << d[i++] << " "; } 66 | cout << "\n"; 67 | 68 | // finally dispose of the object 69 | delete x; 70 | } 71 | 72 | // integer constant assignment test 73 | int ia[6] = { 1, 4, 6, 3, 5 , 2 }; 74 | Rinteger *ri = new Rinteger(ia, 6); 75 | rc->assign("i", ri); 76 | delete ri; 77 | 78 | // let's get the whole iris data 79 | Rvector *iris = (Rvector*) rc->eval("data(iris); iris"); 80 | if (!iris) { cout << "oops! couldn't get iris data\n"; delete rc; return 0; } 81 | 82 | // now let's just get the sepal width - this a cheap operation, no talking to Rserve, because we have all the data already 83 | Rdouble *sw = (Rdouble*) iris->byName("Sepal.Width"); 84 | double *swd = sw->doubleArray(); 85 | 86 | // and print it ... 87 | { int i=0, ct=sw->length(); while (i] [-c ] [-w ] [-n] [-p ] [-s ] [-u ] [-P ] [-h] [ [...]]\n\n", av[0]); 63 | return 0; 64 | } 65 | 66 | if (host_name) { 67 | if (port > 1) rc = new Rconnection(host_name, port); 68 | else rc = new Rconnection(host_name); 69 | } else if (sock_name) { 70 | rc = new Rconnection(sock_name, -1); 71 | } else { 72 | rc = new Rconnection(); 73 | } 74 | 75 | buf[1023]=0; 76 | 77 | i = rc->connect(); 78 | if (i) { 79 | sockerrorchecks(buf, 1023, -1); 80 | fprintf(stderr, "unable to connect (result=%d, socket:%s).\n", i, buf); 81 | return i; 82 | } 83 | 84 | if (user) { 85 | if (!pwd) pwd = ""; 86 | i = rc->login(user, pwd); 87 | if (i) { 88 | fprintf(stderr, "login failed (result=%d)\n", i); 89 | return i; 90 | } 91 | } 92 | 93 | if (do_cd) { 94 | char *es, *d; 95 | const char *c; 96 | if (!wd) 97 | wd = strdup(getwd(buf)); 98 | d = es = (char*) malloc(strlen(wd) * 2 + 14); 99 | c = wd; 100 | strcpy(d, "setwd(\""); d += 7; 101 | while (*c) { 102 | if (*c == '\"' || *c == '\\' || *c == '\'') (d++)[0] = '\\'; 103 | if (*c == '\n' || *c == '\r') (d++)[0] = ' '; else (d++)[0] = (c++)[0]; 104 | } 105 | strcpy(d, "\")"); 106 | rc->voidEval(es); 107 | free(es); 108 | } 109 | 110 | i = 1; 111 | // source all files specified at the command line and print the output 112 | while (i < ac) { 113 | if (av[i][0] == '-') { 114 | switch(av[i][1]) { /* skip options that have extra argument */ 115 | case 'c': 116 | if (++i < ac) { 117 | snprintf(buf, 1023, "try(paste(capture.output(%s),collapse='\\n'))", av[i]); 118 | Rstring *str = (Rstring*) rc->eval(buf); 119 | puts(str->string()); 120 | delete str; 121 | } 122 | break; 123 | case 'p': 124 | case 'P': 125 | case 's': 126 | case 'H': 127 | case 'u': 128 | case 'w': 129 | i++; 130 | } 131 | } else { 132 | snprintf(buf, 1023, "try(paste(capture.output(source(\"%s\")),collapse='\\n'))", av[i]); 133 | Rstring *str = (Rstring*) rc->eval(buf); 134 | puts(str->string()); 135 | delete str; 136 | } 137 | i++; 138 | } 139 | 140 | // dispose of the connection object - this implicitly closes the connection 141 | delete rc; 142 | 143 | return 0; 144 | } 145 | -------------------------------------------------------------------------------- /Rserve/src/client/cxx/rcons.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple console that uses C++ interface to Rserve 3 | * Copyright (C) 2004 Simon Urbanek, All rights reserved. 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation; version 2.1 of the License 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Leser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | * 18 | * $Id: rcons.cc 245 2008-11-25 15:16:27Z urbanek $ 19 | */ 20 | 21 | #include 22 | using std::cout; 23 | 24 | #define MAIN // we are the main program, we need to define this 25 | #define SOCK_ERRORS // we will use verbose socket errors 26 | 27 | #include "Rconnection.h" 28 | #ifdef READLINE 29 | #include 30 | #include 31 | #endif 32 | 33 | #ifdef READLINE 34 | char *c=0; 35 | #else 36 | char c[1024]; 37 | #endif 38 | 39 | int main(int argc, char **argv) { 40 | initsocks(); // this is needed for Win32 - it does noting on unix 41 | 42 | Rconnection *rc = new Rconnection(); 43 | 44 | int i=rc->connect(); 45 | if (i) { 46 | char msg[128]; 47 | sockerrorchecks(msg, 128, -1); 48 | printf("unable to connect (result=%d, socket:%s).\n", i, msg); return i; 49 | } 50 | printf("connected. Type \"q\" to quit.\n"); 51 | 52 | do { 53 | #ifdef READLINE 54 | c=readline("Rcli> "); 55 | if (c && *c) add_history(c); 56 | #else 57 | printf("Rcli> "); 58 | c[1023]=0; 59 | fgets(c,1023,stdin); 60 | char *rq=c; while(*rq && rq-c<1023) { if (*rq=='\n') *rq=0; rq++; } 61 | #endif 62 | 63 | if (!strcmp(c,"q") || !strcmp(c,"quit") || !strcmp(c,"exit")) { 64 | cout << "ok, you got enough, right? leaving.\n"; 65 | break; 66 | } 67 | int res=0; 68 | if (!strcmp(c,"shutdown")) { // this is a demo of low-level commands being send via "request" 69 | Rmessage *msg=new Rmessage(); 70 | cout << "performing shutdown.\n"; 71 | res=rc->request(msg,CMD_shutdown); 72 | delete(msg); 73 | } else if (*c) { // this is a regular "eval" demo 74 | Rexp *xp=rc->eval(c, &res); 75 | if (xp) { 76 | cout << "type=" << xp->type << ", len=" << xp->len << ", result:" << *xp << "\n"; 77 | if (xp->attr) cout << "attributes: " << *xp->attr << "\n"; 78 | delete(xp); 79 | } else cout << "eval failed with result " << res << "\n"; 80 | } 81 | if (res) { 82 | cout << "request failed with error code " << res << "\n"; 83 | break; 84 | } 85 | } while (1); 86 | 87 | delete(rc); 88 | 89 | return 0; 90 | } 91 | -------------------------------------------------------------------------------- /Rserve/src/client/cxx/rsdown.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Small Rserve shutdown program 3 | * Copyright (C) 2004-8 Simon Urbanek, All rights reserved. 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | * 19 | * $Id: demo1.cc 203 2007-05-10 18:12:06Z urbanek $ 20 | */ 21 | 22 | #define MAIN // we are the main program, we need to define this 23 | #define SOCK_ERRORS // we will use verbose socket errors 24 | 25 | #include "sisocks.h" 26 | #include "Rconnection.h" 27 | 28 | int main(int ac, char **av) { 29 | initsocks(); // this is needed for Win32 - it does nothing on unix 30 | 31 | Rconnection *rc = 0; 32 | int port = -1, help = 0; 33 | const char *sock_name = 0; 34 | const char *host_name = 0; 35 | const char *pwd = 0; 36 | 37 | int i = 1; 38 | while (i < ac) { 39 | if (av[i][0] == '-') { 40 | switch (av[i][1]) { 41 | case 'h': help = 1; break; 42 | case 'p': if (++i < ac) port = atoi(av[i]); break; 43 | case 'P': if (++i < ac) pwd = av[i]; else pwd = getpass("password: "); break; 44 | case 's': if (++i < ac) sock_name = av[i]; break; 45 | } 46 | } else if (!host_name) host_name = av[i]; 47 | i++; 48 | } 49 | 50 | if (help) { 51 | printf("\n Usage: %s [] [-p ] [-s ] [-P ] [-h] \n\n", av[0]); 52 | return 0; 53 | } 54 | if (host_name) { 55 | if (port > 1) rc = new Rconnection(host_name, port); 56 | else rc = new Rconnection(host_name); 57 | } else if (sock_name) { 58 | rc = new Rconnection(sock_name, -1); 59 | } else { 60 | rc = new Rconnection(); 61 | } 62 | 63 | i = rc->connect(); 64 | if (i) { 65 | char buf[1024]; 66 | sockerrorchecks(buf, 1024, -1); 67 | fprintf(stderr, "ERROR: unable to connect (result=%d, socket:%s).\n", i, buf); 68 | } else 69 | rc->shutdown(pwd); 70 | delete rc; 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/JRI/Makefile: -------------------------------------------------------------------------------- 1 | ## there are two ways to compile JRIEngine - either use 2 | ## already installed REngine and JRI and then just 3 | ## compile JRIEngine against those jars or use this 4 | ## Makefile with all org sources checked out 5 | ## in which case the JRIEngine.jar will implicitly 6 | ## contain org.rosuda.JRI classes as well 7 | ## However, that requires both: 8 | ## org/rosuda/JRI 9 | ## org/rosuda/REngine 10 | 11 | JRI_MAIN_SRC=$(wildcard ../../JRI/*.java) 12 | JRIENGINE_SRC=JRIEngine.java 13 | 14 | JAVAC=javac 15 | JAR=jar 16 | JFLAGS=-source 1.4 -target 1.4 17 | 18 | all: JRIEngine.jar 19 | 20 | JRIEngine.jar: $(JRI_MAIN_SRC) $(JRIENGINE_SRC) 21 | rm -rf org 22 | $(JAVAC) $(JFLAGS) -classpath ../REngine.jar -d . $^ 23 | $(JAR) fc $@ org 24 | 25 | clean: 26 | rm -rf org *~ JRIEngine.jar *.class 27 | make -C test clean 28 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/JRI/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * REngine-based interface to JRI 3 | * 4 | *

5 | * Currently it uses low-level calls from org.rosuda.JRI.Rengine, but 6 | * all REXP representations are created based on the org.rosuda.REngine API 7 | */ 8 | package org.rosuda.REngine.JRI ; 9 | 10 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/JRI/test/Makefile: -------------------------------------------------------------------------------- 1 | ## NOTE: the tests require rJava to be installed in the current R 2 | ## since they also test the JRI/rJava connectivity 3 | 4 | CP=../../REngine.jar:../JRIEngine.jar:$(RJAVA)/java/boot 5 | JFLAGS=-source 1.4 -target 1.4 6 | 7 | RJAVA=$(shell echo "cat(system.file(package='rJava'))"|R --slave --no-save) 8 | JRI=$(shell if test -e ../../../JRI/src/JRI.jar; then echo ../../../JRI/src; else echo $(RJAVA)/jri; fi) 9 | 10 | JRT=-Djava.library.path=$(JRI):. 11 | 12 | JAVAC=javac 13 | JAVA=java 14 | 15 | all: run 16 | 17 | RTest.class: RTest.java 18 | $(JAVAC) $(JFLAGS) -classpath $(CP) $^ 19 | 20 | run: RTest.class 21 | R CMD $(JAVA) -cp $(CP):. $(JRT) RTest 22 | 23 | clean: 24 | rm -rf org *.class *~ 25 | 26 | .PHONY: run clean 27 | 28 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/LICENSE: -------------------------------------------------------------------------------- 1 | REngine - Java interface to R 2 | Copyright (C) 2004,5,6,7 Simon Urbanek 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/Makefile: -------------------------------------------------------------------------------- 1 | RENG_SRC=$(wildcard *.java) 2 | RSRV_SRC=$(wildcard Rserve/*.java) $(wildcard Rserve/protocol/*.java) 3 | JRI_SRC=$(wildcard JRI/*.java) 4 | 5 | TARGETS=REngine.jar Rserve.jar 6 | 7 | all: $(TARGETS) 8 | 9 | JAVAC=javac 10 | JAVADOC=javadoc 11 | JDFLAGS=-author -version -breakiterator -link http://java.sun.com/j2se/1.4.2/docs/api/ 12 | JFLAGS+=-source 1.4 -target 1.4 13 | 14 | REngine.jar: $(RENG_SRC) 15 | @rm -rf org 16 | $(JAVAC) -d . $(JFLAGS) $(RENG_SRC) 17 | jar fc $@ org 18 | rm -rf org 19 | 20 | Rserve.jar: $(RSRV_SRC) REngine.jar 21 | @rm -rf org 22 | $(JAVAC) -d . -cp REngine.jar $(RSRV_SRC) 23 | jar fc $@ org 24 | rm -rf org 25 | 26 | clean: 27 | rm -rf org *~ $(TARGETS) doc 28 | make -C Rserve clean 29 | make -C JRI clean 30 | 31 | test: 32 | make -C Rserve test 33 | 34 | rc: Rserve.jar Rserve/test/jt.java 35 | make -C Rserve/test jt 36 | 37 | doc: $(RENG_SRC) $(RSRV_SRC) $(JRI_SRC) 38 | rm -rf $@ 39 | mkdir $@ 40 | $(JAVADOC) -d $@ $(JDFLAGS) $^ 41 | 42 | .PHONY: clean all test 43 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/MutableREXP.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | public interface MutableREXP { 4 | public void setAttribute(String name, REXP value); 5 | } 6 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REXPDouble.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** REXPDouble represents a vector of double precision floating point values. */ 4 | public class REXPDouble extends REXPVector { 5 | private double[] payload; 6 | 7 | /** NA real value as defined in R. Note: it can NOT be used in comparisons, you must use {@link #isNA(double)} instead. */ 8 | public static final double NA = Double.longBitsToDouble(0x7ff00000000007a2L); 9 | 10 | /** Java screws up the bits in NA real values, so we cannot compare to the real bits used by R (0x7ff00000000007a2L) but use this value which is obtained by passing the bits through Java's double type */ 11 | static final long NA_bits = Double.doubleToRawLongBits(Double.longBitsToDouble(0x7ff00000000007a2L)); 12 | 13 | /** checks whether a given double value is a NA representation in R. Note that NA is NaN but not all NaNs are NA. */ 14 | public static boolean isNA(double value) { 15 | return Double.doubleToRawLongBits(value) == NA_bits; 16 | } 17 | 18 | /** create real vector of the length 1 with the given value as its first (and only) element */ 19 | public REXPDouble(double load) { 20 | super(); 21 | payload=new double[] { load }; 22 | } 23 | 24 | public REXPDouble(double[] load) { 25 | super(); 26 | payload=(load==null)?new double[0]:load; 27 | } 28 | 29 | public REXPDouble(double[] load, REXPList attr) { 30 | super(attr); 31 | payload=(load==null)?new double[0]:load; 32 | } 33 | 34 | public int length() { return payload.length; } 35 | 36 | /** return true */ 37 | public boolean isNumeric() { return true; } 38 | 39 | /** returns the values represented by this vector */ 40 | public double[] asDoubles() { return payload; } 41 | 42 | /** converts the values of this vector into integers by cast */ 43 | public int[] asIntegers() { 44 | int[] a = new int[payload.length]; 45 | int i = 0; 46 | while (i < payload.length) { a[i] = (int) payload[i]; i++; } 47 | return a; 48 | } 49 | 50 | /** converts the values of this vector into strings */ 51 | public String[] asStrings() { 52 | String[] s = new String[payload.length]; 53 | int i = 0; 54 | while (i < payload.length) { s[i] = ""+payload[i]; i++; } 55 | return s; 56 | } 57 | 58 | /** returns a boolean vector of the same length as this vector with true for NA values and false for any other values (including NaNs) */ 59 | public boolean[] isNA() { 60 | boolean a[] = new boolean[payload.length]; 61 | int i = 0; 62 | while (i < a.length) { a[i] = isNA(payload[i]); i++; } 63 | return a; 64 | } 65 | 66 | public String toDebugString() { 67 | StringBuffer sb = new StringBuffer(super.toDebugString()+"{"); 68 | int i = 0; 69 | while (i < payload.length && i < maxDebugItems) { 70 | if (i>0) sb.append(","); 71 | sb.append(payload[i]); 72 | i++; 73 | } 74 | if (i < payload.length) sb.append(",.."); 75 | return sb.toString()+"}"; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REXPEnvironment.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | // environments are like REXPReferences except that they cannot be resolved 3 | 4 | /** REXPEnvironment represents an environment in R. Very much like {@link org.rosuda.REngine.REXPReference} this is a proxy object to the actual object on the R side. It provides methods for accessing the content of the environment. The actual implementation may vary by the back-end used and not all engines support environments. Check {@link org.rosuda.REngine.REngine.supportsEnvironments()} for the given engine. Environments are specific for a given engine, they cannot be passed across engines. 5 | */ 6 | public class REXPEnvironment extends REXP { 7 | /** engine associated with this environment */ 8 | REngine eng; 9 | /** transparent handle that can be used by the engine to indentify the environment. It is not used by REngine API itself. */ 10 | Object handle; 11 | 12 | /** create a new environemnt reference - this constructor should never be used directly, use {@link REngine.newEnvironment()} instead. 13 | * @param eng engine responsible for this environment 14 | * @param handle handle used by the engine to identify this environment 15 | */ 16 | public REXPEnvironment(REngine eng, Object handle) { 17 | super(); 18 | this.eng = eng; 19 | this.handle = handle; 20 | } 21 | 22 | public boolean isEnvironment() { return true; } 23 | 24 | /** returns the handle used to identify this environemnt in the engine - for internal use by engine implementations only 25 | * @return handle of this environment */ 26 | public Object getHandle() { return handle; } 27 | 28 | /** get a value from this environment 29 | * @param name name of the value 30 | * @param resolve if false returns a reference to the object, if false the reference is resolved 31 | * @return value corresponding to the symbol name or possibly null if the value is unbound (the latter is currently engine-specific) */ 32 | public REXP get(String name, boolean resolve) throws REngineException { 33 | try { 34 | return eng.get(name, this, resolve); 35 | } catch (REXPMismatchException e) { // this should never happen because this is always guaranteed to be REXPEnv 36 | throw(new REngineException(eng, "REXPMismatchException:"+e+" in get()")); 37 | } 38 | } 39 | 40 | /** get a value from this environment - equavalent to get(name, true). 41 | * @param name name of the value 42 | * @return value (see {@link #get(String,boolean)}) */ 43 | public REXP get(String name) throws REngineException { 44 | return get(name, true); 45 | } 46 | 47 | /** assigns a value to a given symbol name 48 | * @param name symbol name 49 | * @param value value */ 50 | public void assign(String name, REXP value) throws REngineException, REXPMismatchException { 51 | eng.assign(name, value, this); 52 | } 53 | 54 | /** returns the parent environment or a reference to it 55 | * @param resolve if true returns the environemnt, otherwise a reference. 56 | * @return parent environemnt (or a reference to it) */ 57 | public REXP parent(boolean resolve) throws REngineException { 58 | try { 59 | return eng.getParentEnvironment(this, resolve); 60 | } catch (REXPMismatchException e) { // this should never happen because this is always guaranteed to be REXPEnv 61 | throw(new REngineException(eng, "REXPMismatchException:"+e+" in parent()")); 62 | } 63 | } 64 | 65 | /** returns the parent environment. This is equivalent to parent(true). 66 | * @return parent environemnt */ 67 | public REXPEnvironment parent() throws REngineException { 68 | return (REXPEnvironment) parent(true); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REXPExpressionVector.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** REXPExpressionVector represents a vector of expressions in R. It is essentially a special kind of generic vector - its elements are expected to be valid R expressions. */ 4 | public class REXPExpressionVector extends REXPGenericVector { 5 | /** create a new vector of expressions from a list of expressions. 6 | * @param list list of expressions to store in this vector */ 7 | public REXPExpressionVector(RList list) { super(list); } 8 | 9 | /** create a new vector of expressions from a list of expressions. 10 | * @param list list of expressions to store in this vector 11 | * @param attr attributes for the R object */ 12 | public REXPExpressionVector(RList list, REXPList attr) { super(list, attr); } 13 | 14 | public boolean isExpression() { return true; } 15 | } 16 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REXPFactor.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** REXPFactor represents a factor in R. It is an integer vector with levels for each contained category. */ 4 | // FIXME: this is currently somehow screwed - the concept of RFactor and REXPFactor is duplicate - we need to remove this historical baggage 5 | public class REXPFactor extends REXPInteger { 6 | private String[] levels; 7 | private RFactor factor; 8 | 9 | /** create a new factor REXP 10 | * @param ids indices (one-based!) 11 | * @param levels levels */ 12 | public REXPFactor(int[] ids, String[] levels) { 13 | super(ids); 14 | this.levels = (levels==null)?(new String[0]):levels; 15 | factor = new RFactor(this.payload, this.levels, false, 1); 16 | attr = new REXPList( 17 | new RList( 18 | new REXP[] { 19 | new REXPString(this.levels), new REXPString("factor") 20 | }, new String[] { "levels", "class" })); 21 | } 22 | 23 | /** create a new factor REXP 24 | * @param ids indices (one-based!) 25 | * @param levels levels 26 | * @param attr attributes */ 27 | public REXPFactor(int[] ids, String[] levels, REXPList attr) { 28 | super(ids, attr); 29 | this.levels = (levels==null)?(new String[0]):levels; 30 | factor = new RFactor(this.payload, this.levels, false, 1); 31 | } 32 | 33 | /** create a new factor REXP from an existing RFactor 34 | * @param factor factor object (can be of any index base, the contents will be pulled with base 1) */ 35 | public REXPFactor(RFactor factor) { 36 | super(factor.asIntegers(1)); 37 | this.factor = factor; 38 | this.levels = factor.levels(); 39 | attr = new REXPList( 40 | new RList( 41 | new REXP[] { 42 | new REXPString(this.levels), new REXPString("factor") 43 | }, new String[] { "levels", "class" })); 44 | } 45 | 46 | /** create a new factor REXP from an existing RFactor 47 | * @param factor factor object (can be of any index base, the contents will be pulled with base 1) 48 | * @param attr attributes */ 49 | public REXPFactor(RFactor factor, REXPList attr) { 50 | super(factor.asIntegers(1), attr); 51 | this.factor = factor; 52 | this.levels = factor.levels(); 53 | } 54 | 55 | public boolean isFactor() { return true; } 56 | 57 | /** return the contents as a factor - the factor is guaranteed to have index base 1 58 | * @return the contents as a factor */ 59 | public RFactor asFactor() { 60 | return factor; 61 | } 62 | 63 | public String[] asStrings() { 64 | return factor.asStrings(); 65 | } 66 | 67 | public String toString() { 68 | return super.toString()+"["+levels.length+"]"; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REXPGenericVector.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** REXPGenericVector represents a generic vector in R. Its elements can be typically of any {@link REXP} type. */ 4 | public class REXPGenericVector extends REXPVector { 5 | /** payload */ 6 | private RList payload; 7 | 8 | /** creates a new generic vector from a list. If the list is named, the "names" attribute is created automatically from it. 9 | * @param list list to create the vector from */ 10 | public REXPGenericVector(RList list) { 11 | super(); 12 | payload=(list==null)?new RList():list; 13 | // automatically generate 'names' attribute 14 | if (payload.isNamed()) 15 | attr = new REXPList( 16 | new RList(new REXP[] { new REXPString(payload.keys()) }, 17 | new String[] { "names" })); 18 | } 19 | 20 | /** creates a new generic vector from a list. Note that the names in the list are ignored as they are expected to be defined by the attributes parameter. 21 | * @param list list to create the vector from (names are ignored - use {@link #REXPGenericVector(RList)} or the "names" attribute for named lists 22 | * @param attr attributes */ 23 | public REXPGenericVector(RList list, REXPList attr) { 24 | super(attr); 25 | payload=(list==null)?new RList():list; 26 | } 27 | 28 | public int length() { return payload.size(); } 29 | 30 | public boolean isList() { return true; } 31 | 32 | public boolean isRecursive() { return true; } 33 | 34 | public RList asList() { return payload; } 35 | 36 | public String toString() { 37 | return super.toString()+(asList().isNamed()?"named":""); 38 | } 39 | 40 | public String toDebugString() { 41 | StringBuffer sb = new StringBuffer(super.toDebugString()+"{"); 42 | int i = 0; 43 | while (i < payload.size() && i < maxDebugItems) { 44 | if (i>0) sb.append(",\n"); 45 | sb.append(payload.at(i).toDebugString()); 46 | i++; 47 | } 48 | if (i < payload.size()) sb.append(",.."); 49 | return sb.toString()+"}"; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REXPInteger.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** REXPDouble represents a vector of integer values. */ 4 | public class REXPInteger extends REXPVector { 5 | protected int[] payload; 6 | 7 | /** NA integer value as defined in R. Unlike its real equivalent this one can be used in comparisons, although {@link #isNA(int) } is provided for consistency. */ 8 | public static final int NA = -2147483648; 9 | 10 | public static boolean isNA(int value) { 11 | return (value == NA); 12 | } 13 | 14 | /** create integer vector of the length 1 with the given value as its first (and only) element */ 15 | public REXPInteger(int load) { 16 | super(); 17 | payload=new int[] { load }; 18 | } 19 | 20 | /** create integer vector with the payload specified by load */ 21 | public REXPInteger(int[] load) { 22 | super(); 23 | payload=(load==null)?new int[0]:load; 24 | } 25 | 26 | /** create integer vector with the payload specified by load and attributes attr */ 27 | public REXPInteger(int[] load, REXPList attr) { 28 | super(attr); 29 | payload=(load==null)?new int[0]:load; 30 | } 31 | 32 | public int length() { return payload.length; } 33 | 34 | public boolean isInteger() { return true; } 35 | public boolean isNumeric() { return true; } 36 | 37 | public int[] asIntegers() { return payload; } 38 | 39 | /** returns the contents of this vector as doubles */ 40 | public double[] asDoubles() { 41 | double[] d = new double[payload.length]; 42 | int i = 0; 43 | while (i < payload.length) { d[i] = (double) payload[i]; i++; } 44 | return d; 45 | } 46 | 47 | /** returns the contents of this vector as strings */ 48 | public String[] asStrings() { 49 | String[] s = new String[payload.length]; 50 | int i = 0; 51 | while (i < payload.length) { s[i] = ""+payload[i]; i++; } 52 | return s; 53 | } 54 | 55 | public boolean[] isNA() { 56 | boolean a[] = new boolean[payload.length]; 57 | int i = 0; 58 | while (i < a.length) { a[i] = (payload[i]==NA); i++; } 59 | return a; 60 | } 61 | 62 | public String toDebugString() { 63 | StringBuffer sb = new StringBuffer(super.toDebugString()+"{"); 64 | int i = 0; 65 | while (i < payload.length && i < maxDebugItems) { 66 | if (i>0) sb.append(","); 67 | sb.append(payload[i]); 68 | i++; 69 | } 70 | if (i < payload.length) sb.append(",.."); 71 | return sb.toString()+"}"; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REXPLanguage.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** represents a language object in R */ 4 | public class REXPLanguage extends REXPList { 5 | public REXPLanguage(RList list) { super(list); } 6 | public REXPLanguage(RList list, REXPList attr) { super(list, attr); } 7 | 8 | public boolean isLanguage() { return true; } 9 | } 10 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REXPList.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** represents a pairlist in R */ 4 | public class REXPList extends REXPVector { 5 | private RList payload; 6 | 7 | public REXPList(RList list) { 8 | super(); 9 | payload=(list==null)?new RList():list; 10 | } 11 | 12 | public REXPList(RList list, REXPList attr) { 13 | super(attr); 14 | payload=(list==null)?new RList():list; 15 | } 16 | 17 | public int length() { return payload.size(); } 18 | 19 | public boolean isList() { return true; } 20 | public boolean isPairList() { return true; } 21 | 22 | public boolean isRecursive() { return true; } 23 | 24 | public RList asList() { return payload; } 25 | 26 | public String toString() { 27 | return super.toString()+(asList().isNamed()?"named":""); 28 | } 29 | 30 | public String toDebugString() { 31 | StringBuffer sb = new StringBuffer(super.toDebugString()+"{"); 32 | int i = 0; 33 | while (i < payload.size() && i < maxDebugItems) { 34 | if (i>0) sb.append(",\n"); 35 | String name = payload.keyAt(i); 36 | if (name!=null) sb.append(name+"="); 37 | sb.append(payload.at(i).toDebugString()); 38 | i++; 39 | } 40 | if (i < payload.size()) sb.append(",.."); 41 | return sb.toString()+"}"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REXPLogical.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** REXPLogical represents a vector of logical values (TRUE, FALSE or NA). Unlike Java's boolean type R's logicals support NA values therefore either of {@link #isTRUE()}, {@link #isFALSE()} or {@link #isNA()} must be used to convert logicals to boolean values. */ 4 | public class REXPLogical extends REXPVector { 5 | protected byte[] payload; 6 | 7 | /** NA integer value as defined in R. Unlike its real equivalent this one can be used in comparisons, although {@link #isNA(int) } is provided for consistency. */ 8 | static final int NA_internal = -2147483648; 9 | 10 | /** NA boolean value as used in REXPLogical implementation. This differs from the value used in R since R uses int data type and we use byte. Unlike its real equivalent this one can be used in comparisons, although {@link #isNA(byte) } is provided for consistency. */ 11 | public static final byte NA = -128; 12 | public static final byte TRUE = 1; 13 | public static final byte FALSE = 0; 14 | 15 | public static boolean isNA(byte value) { 16 | return (value == NA); 17 | } 18 | 19 | /** create logical vector of the length 1 with the given value as its first (and only) element */ 20 | public REXPLogical(boolean load) { 21 | super(); 22 | payload = new byte[] { load ? TRUE : FALSE }; 23 | } 24 | 25 | /** create logical vector of the length 1 with the given value as its first (and only) element */ 26 | public REXPLogical(byte load) { 27 | super(); 28 | payload = new byte[] { load }; 29 | } 30 | 31 | /** create logical vector with the payload specified by load */ 32 | public REXPLogical(byte[] load) { 33 | super(); 34 | payload = (load==null) ? new byte[0]:load; 35 | } 36 | 37 | /** create logical vector with the payload specified by load */ 38 | public REXPLogical(boolean[] load) { 39 | super(); 40 | payload = new byte[(load == null) ? 0 : load.length]; 41 | if (load != null) 42 | for (int i = 0; i < load.length; i++) 43 | payload[i] = load[i] ? TRUE : FALSE; 44 | } 45 | 46 | /** create integer vector with the payload specified by load and attributes attr */ 47 | public REXPLogical(byte[] load, REXPList attr) { 48 | super(attr); 49 | payload = (load==null) ? new byte[0] : load; 50 | } 51 | 52 | /** create integer vector with the payload specified by load and attributes attr */ 53 | public REXPLogical(boolean[] load, REXPList attr) { 54 | super(attr); 55 | payload = new byte[(load == null) ? 0 : load.length]; 56 | if (load != null) 57 | for (int i = 0; i < load.length; i++) 58 | payload[i] = load[i] ? TRUE : FALSE; 59 | } 60 | 61 | public int length() { return payload.length; } 62 | 63 | public boolean isLogical() { return true; } 64 | 65 | public int[] asIntegers() { 66 | int p[] = new int[payload.length]; 67 | for (int i = 0; i < payload.length; i++) // map bytes to integers including NA representation 68 | p[i] = (payload[i] == NA) ? REXPInteger.NA : ((payload[i] == FALSE) ? 0 : 1); 69 | return p; 70 | } 71 | 72 | public byte[] asBytes() { return payload; } 73 | 74 | /** returns the contents of this vector as doubles */ 75 | public double[] asDoubles() { 76 | double[] d = new double[payload.length]; 77 | for (int i = 0; i < payload.length; i++) 78 | d[i] = (payload[i] == NA) ? REXPDouble.NA : ((payload[i] == FALSE) ? 0.0 : 1.0); 79 | return d; 80 | } 81 | 82 | /** returns the contents of this vector as strings */ 83 | public String[] asStrings() { 84 | String[] s = new String[payload.length]; 85 | for (int i = 0; i < payload.length; i++) 86 | s[i] = (payload[i] == NA) ? "NA" : ((payload[i] == FALSE) ? "FALSE" : "TRUE"); 87 | return s; 88 | } 89 | 90 | public boolean[] isNA() { 91 | boolean a[] = new boolean[payload.length]; 92 | int i = 0; 93 | while (i < a.length) { a[i] = (payload[i] == NA); i++; } 94 | return a; 95 | } 96 | 97 | /** returns a boolean array of the same langth as the receiver with true for TRUE values and false for FALSE and NA values. 98 | @return boolean array */ 99 | public boolean[] isTRUE() { 100 | boolean a[] = new boolean[payload.length]; 101 | int i = 0; 102 | while (i < a.length) { a[i] = (payload[i] != NA && payload[i] != FALSE); i++; } 103 | return a; 104 | } 105 | 106 | /** returns a boolean array of the same langth as the receiver with true for FALSE values and false for TRUE and NA values. 107 | @return boolean array */ 108 | public boolean[] isFALSE() { 109 | boolean a[] = new boolean[payload.length]; 110 | int i = 0; 111 | while (i < a.length) { a[i] = (payload[i] == FALSE); i++; } 112 | return a; 113 | } 114 | 115 | /** returns a boolean array of the same langth as the receiver with true for TRUE values and false for FALSE and NA values. 116 | @return boolean array 117 | @deprecated replaced by {@link #isTRUE()} for consistency with R nomenclature. */ 118 | public boolean[] isTrue() { return isTRUE(); } 119 | 120 | /** returns a boolean array of the same langth as the receiver with true for FALSE values and false for TRUE and NA values. 121 | @return boolean array 122 | @deprecated replaced by {@link #isTRUE()} for consistency with R nomenclature. */ 123 | public boolean[] isFalse() { return isFALSE(); } 124 | 125 | public String toDebugString() { 126 | StringBuffer sb = new StringBuffer(super.toDebugString()+"{"); 127 | int i = 0; 128 | while (i < payload.length && i < maxDebugItems) { 129 | if (i>0) sb.append(","); 130 | sb.append((payload[i] == NA) ? "NA" : ((payload[i] == FALSE) ? "FALSE" : "TRUE")); 131 | i++; 132 | } 133 | if (i < payload.length) sb.append(",.."); 134 | return sb.toString()+"}"; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REXPMismatchException.java: -------------------------------------------------------------------------------- 1 | // REngine - generic Java/R API 2 | // 3 | // Copyright (C) 2007,2008 Simon Urbanek 4 | // --- for licensing information see LICENSE file in the distribution --- 5 | // 6 | // REXPMismatch.java 7 | // 8 | // Created by Simon Urbanek on 2007/05/03 9 | // 10 | // $Id: REngineException.java 2555 2006-06-21 20:36:42Z urbaneks $ 11 | // 12 | 13 | package org.rosuda.REngine; 14 | 15 | /** This exception is thrown whenever the operation requested is not supported by the given R object type, e.g. using asStrings on an S4 object. Most {@link REXP} methods throw this exception. Previous R/Java interfaces were silently returning null in those cases, but using exceptions helps to write more robust code. */ 16 | public class REXPMismatchException extends Exception { 17 | REXP sender; 18 | String access; 19 | 20 | /** primary constructor. The exception message will be formed as "attempt to access <REXP-class> as <access-string>" 21 | * @param sender R object that triggered this exception (cannot be null!) 22 | * @param access assumed type of the access that was requested. It should be a simple name of the assumed type (e.g. "vector"). The type name can be based on R semantics beyond basic types reflected by REXP classes. In cases where certain assertions were not satisfied, the string should be of the form "type (assertion)" (e.g. "data frame (must have dim>0)"). */ 23 | public REXPMismatchException(REXP sender, String access) { 24 | super("attempt to access "+sender.getClass().getName()+" as "+access); 25 | this.sender = sender; 26 | this.access = access; 27 | } 28 | 29 | /** retrieve the exception sender/origin 30 | * @return REXP object that triggered the exception */ 31 | public REXP getSender() { 32 | return sender; 33 | } 34 | 35 | /** get the assumed access type that was violated by the sender. 36 | * @return string describing the access type. See {@link #REXPMismatchException} for details. */ 37 | public String getAccess() { 38 | return access; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REXPNull.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** represents a NULL object in R. 4 |

5 | Note: there is a slight asymmetry - in R NULL is represented by a zero-length pairlist. For this reason REXPNull returns true for {@link #isList()} and {@link #asList()} will return an empty list. Nonetheless REXPList of the length 0 will NOT return true in {@link #isNull()} (currently), becasue it is considered a different object in Java. These nuances are still subject to change, because it's not clear how it should be treated. At any rate use REXPNull instead of empty REXPList if NULL is the intended value. 6 | */ 7 | public class REXPNull extends REXP { 8 | public REXPNull() { super(); } 9 | public REXPNull(REXPList attr) { super(attr); } 10 | 11 | public boolean isNull() { return true; } 12 | public boolean isList() { return true; } // NULL is a list 13 | public RList asList() { return new RList(); } 14 | } 15 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REXPRaw.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** REXPRaw represents a raw vector in R - essentially a sequence of bytes. */ 4 | public class REXPRaw extends REXPVector { 5 | private byte[] payload; 6 | 7 | /** create a new raw vector with the specified payload 8 | * @param load payload of the raw vector */ 9 | public REXPRaw(byte[] load) { 10 | super(); 11 | payload=(load==null)?new byte[0]:load; 12 | } 13 | 14 | /** create a new raw vector with the specified payload and attributes 15 | * @param load payload of the raw vector 16 | * @param attr attributes for the resulting R object */ 17 | public REXPRaw(byte[] load, REXPList attr) { 18 | super(attr); 19 | payload=(load==null)?new byte[0]:load; 20 | } 21 | 22 | public int length() { return payload.length; } 23 | 24 | public boolean isRaw() { return true; } 25 | 26 | public byte[] asBytes() { return payload; } 27 | } 28 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REXPReference.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** this class represents a reference (proxy) to an R object. 4 |

5 | The reference semantics works by calling {@link #resolve()} (which in turn uses {@link REngine#resolveReference(REXP)} on itself) whenever any methods are accessed. The implementation is not finalized yat and may change as we approach the JRI interface which is more ameanable to reference-style access. Subclasses are free to implement more efficient implementations. */ 6 | public class REXPReference extends REXP { 7 | /** engine which will be used to resolve the reference */ 8 | protected REngine eng; 9 | /** an opaque (optional) handle */ 10 | protected Object handle; 11 | /** resolved (cached) object */ 12 | protected REXP resolvedValue; 13 | 14 | /** create an external REXP reference using given engine and handle. The handle value is just an (optional) identifier not used by the implementation directly. */ 15 | public REXPReference(REngine eng, Object handle) { 16 | super(); 17 | this.eng = eng; 18 | this.handle = handle; 19 | } 20 | 21 | /** shortcut for REXPReference(eng, new Long(handle)) that is used by native code */ 22 | REXPReference(REngine eng, long handle) { 23 | this(eng, new Long(handle)); 24 | } 25 | 26 | /** resolve the external REXP reference into an actual REXP object. In addition, the value (if not null) will be cached for subsequent calls to resolve until invalidate is called. */ 27 | public REXP resolve() { 28 | if (resolvedValue != null) 29 | return resolvedValue; 30 | try { 31 | resolvedValue = eng.resolveReference(this); 32 | return resolvedValue; 33 | } catch (REXPMismatchException me) { 34 | // this should never happen since we are REXPReference 35 | } catch(REngineException ee) { 36 | // FIXME: what to we do? 37 | } 38 | return null; 39 | } 40 | 41 | /** invalidates any cached representation of the reference */ 42 | public void invalidate() { 43 | resolvedValue = null; 44 | } 45 | 46 | /** finalization that notifies the engine when a reference gets collected */ 47 | protected void finalize() throws Throwable { 48 | try { 49 | eng.finalizeReference(this); 50 | } finally { 51 | super.finalize(); 52 | } 53 | } 54 | // type checks 55 | public boolean isString() { return resolve().isString(); } 56 | public boolean isNumeric() { return resolve().isNumeric(); } 57 | public boolean isInteger() { return resolve().isInteger(); } 58 | public boolean isNull() { return resolve().isNull(); } 59 | public boolean isFactor() { return resolve().isFactor(); } 60 | public boolean isList() { return resolve().isList(); } 61 | public boolean isLogical() { return resolve().isLogical(); } 62 | public boolean isEnvironment() { return resolve().isEnvironment(); } 63 | public boolean isLanguage() { return resolve().isLanguage(); } 64 | public boolean isSymbol() { return resolve().isSymbol(); } 65 | public boolean isVector() { return resolve().isVector(); } 66 | public boolean isRaw() { return resolve().isRaw(); } 67 | public boolean isComplex() { return resolve().isComplex(); } 68 | public boolean isRecursive() { return resolve().isRecursive(); } 69 | public boolean isReference() { return true; } 70 | 71 | // basic accessor methods 72 | public String[] asStrings() throws REXPMismatchException { return resolve().asStrings(); } 73 | public int[] asIntegers() throws REXPMismatchException { return resolve().asIntegers(); } 74 | public double[] asDoubles() throws REXPMismatchException { return resolve().asDoubles(); } 75 | public RList asList() throws REXPMismatchException { return resolve().asList(); } 76 | public RFactor asFactor() throws REXPMismatchException { return resolve().asFactor(); } 77 | 78 | public int length() throws REXPMismatchException { return resolve().length(); } 79 | 80 | public REXPList _attr() { return resolve()._attr(); } 81 | 82 | public Object getHandle() { return handle; } 83 | 84 | public REngine getEngine() { return eng; } 85 | 86 | public String toString() { 87 | return super.toString()+"{eng="+eng+",h="+handle+"}"; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REXPS4.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** S4 REXP is a completely vanilla REXP */ 4 | public class REXPS4 extends REXP { 5 | public REXPS4() { super(); } 6 | public REXPS4(REXPList attr) { super(attr); } 7 | } 8 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REXPString.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** REXPString represents a character vector in R. */ 4 | public class REXPString extends REXPVector { 5 | /** payload */ 6 | private String[] payload; 7 | 8 | /** create a new character vector of the length one 9 | * @param load first (and only) element of the vector */ 10 | public REXPString(String load) { 11 | super(); 12 | payload=new String[] { load }; 13 | } 14 | 15 | /** create a new character vector 16 | * @param load string elements of the vector */ 17 | public REXPString(String[] load) { 18 | super(); 19 | payload=(load==null)?new String[0]:load; 20 | } 21 | 22 | /** create a new character vector with attributes 23 | * @param load string elements of the vector 24 | * @param attr attributes */ 25 | public REXPString(String[] load, REXPList attr) { 26 | super(attr); 27 | payload=(load==null)?new String[0]:load; 28 | } 29 | 30 | public int length() { return payload.length; } 31 | 32 | public boolean isString() { return true; } 33 | 34 | public String[] asStrings() { 35 | return payload; 36 | } 37 | 38 | public boolean[] isNA() { 39 | boolean a[] = new boolean[payload.length]; 40 | int i = 0; 41 | while (i < a.length) { a[i] = (payload[i]==null); i++; } 42 | return a; 43 | } 44 | 45 | public String toDebugString() { 46 | StringBuffer sb = new StringBuffer(super.toDebugString()+"{"); 47 | int i = 0; 48 | while (i < payload.length && i < maxDebugItems) { 49 | if (i>0) sb.append(","); 50 | sb.append("\""+payload[i]+"\""); 51 | i++; 52 | } 53 | if (i < payload.length) sb.append(",.."); 54 | return sb.toString()+"}"; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REXPSymbol.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** REXPSymbol represents a symbol in R. */ 4 | public class REXPSymbol extends REXP { 5 | /** name of the symbol */ 6 | private String name; 7 | 8 | /** create a new symbol of the given name */ 9 | public REXPSymbol(String name) { 10 | super(); 11 | this.name=(name==null)?"":name; 12 | } 13 | 14 | public boolean isSymbol() { return true; } 15 | 16 | /** returns the name of the symbol 17 | * @return name of the symbol */ 18 | public String asString() { return name; } 19 | 20 | public String[] asStrings() { 21 | return new String[] { name }; 22 | } 23 | 24 | public String toString() { 25 | return getClass().getName()+"["+name+"]"; 26 | } 27 | 28 | public String toDebugString() { 29 | return super.toDebugString()+"["+name+"]"; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REXPUnknown.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** REXPUnknown is a stand-in for an object that cannot be represented in the REngine hierarchy. Usually this class can be encountered when new types are introduced in R or if a given engine doesn't support all data types. Usually REXPUnknown can only be retrieved from the engine but never assigned. */ 4 | public class REXPUnknown extends REXP { 5 | /** type of the unterlying obejct */ 6 | int type; 7 | 8 | /** creates a new unknown object of the given type 9 | * @param type internal R type code of this object */ 10 | public REXPUnknown(int type) { super(); this.type=type; } 11 | 12 | /** creates a new unknown object of the given type 13 | * @param type internal R type code of this object 14 | * @param attr attributes */ 15 | public REXPUnknown(int type, REXPList attr) { super(attr); this.type=type; } 16 | 17 | /** returns the internal R type of this unknown obejct 18 | * @return type code */ 19 | public int getType() { return type; } 20 | 21 | public String toString() { 22 | return super.toString()+"["+type+"]"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REXPVector.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** abstract class representing all vectors in R */ 4 | public abstract class REXPVector extends REXP { 5 | public REXPVector() { super(); } 6 | 7 | public REXPVector(REXPList attr) { 8 | super(attr); 9 | } 10 | 11 | /** returns the length of the vector (i.e. the number of elements) 12 | * @return length of the vector */ 13 | public abstract int length(); 14 | 15 | public boolean isVector() { return true; } 16 | 17 | /** returns a boolean vector of the same length as this vector with true for NA values and false for any other values 18 | * @return a boolean vector of the same length as this vector with true for NA values and false for any other values */ 19 | public boolean[] isNA() { 20 | boolean a[] = new boolean[length()]; 21 | return a; 22 | } 23 | 24 | public String toString() { 25 | return super.toString()+"["+length()+"]"; 26 | } 27 | 28 | public String toDebugString() { 29 | return super.toDebugString()+"["+length()+"]"; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REngineCallbacks.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** REngineCallbacks is a virtual interface that poses as a superclass of all callback delegate classes. */ 4 | public interface REngineCallbacks { 5 | } 6 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REngineConsoleHistoryInterface.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** interface defining delegate methods used by {@link REngine} to forward console history callbacks from R. */ 4 | public interface REngineConsoleHistoryInterface { 5 | /** called when R wants to save the history content. 6 | * @param eng calling engine 7 | * @param filename name of the file to save command history to 8 | */ 9 | public void RSaveHistory (REngine eng, String filename); 10 | 11 | /** called when R wants to load the history content. 12 | * @param eng calling engine 13 | * @param filename name of the file to load the command history from 14 | */ 15 | public void RLoadHistory (REngine eng, String filename); 16 | } 17 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REngineEvalException.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine ; 2 | 3 | /** 4 | * Exception thrown when an error occurs during eval. 5 | * 6 | *

7 | * This class is a placeholder and should be extended when more information 8 | * can be extracted from R (call stack, etc ... ) 9 | *

10 | */ 11 | public class REngineEvalException extends REngineException { 12 | 13 | /** 14 | * Value returned by the rniEval native method when the input passed to eval 15 | * is invalid 16 | */ 17 | public static final int INVALID_INPUT = -1 ; 18 | 19 | /** 20 | * Value returned by the rniEval native method when an error occured during 21 | * eval (stop, ...) 22 | */ 23 | public static final int ERROR = -2 ; 24 | 25 | /** 26 | * Type of eval error 27 | */ 28 | protected int type ; 29 | 30 | /** 31 | * Constructor 32 | * 33 | * @param eng associated REngine 34 | * @param message error message 35 | * @param type type of error (ERROR or INVALID_INPUT) 36 | */ 37 | public REngineEvalException( REngine eng, String message, int type ){ 38 | super( eng, message ); 39 | this.type = type ; 40 | } 41 | 42 | /** 43 | * Constructor using ERROR type 44 | * 45 | * @param eng associated REngine 46 | * @param message error message 47 | */ 48 | public REngineEvalException( REngine eng, String message){ 49 | this( eng, message, ERROR ); 50 | } 51 | 52 | /** 53 | * @return the type of error (ERROR or INVALID_INPUT) 54 | */ 55 | public int getType(){ 56 | return type ; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REngineException.java: -------------------------------------------------------------------------------- 1 | // REngine - generic Java/R API 2 | // 3 | // Copyright (C) 2006 Simon Urbanek 4 | // --- for licensing information see LICENSE file in the original JRclient distribution --- 5 | // 6 | // RSrvException.java 7 | // 8 | // Created by Simon Urbanek on Wed Jun 21 2006. 9 | // 10 | // $Id: REngineException.java 3122 2009-06-17 15:47:41Z urbanek $ 11 | // 12 | 13 | package org.rosuda.REngine; 14 | 15 | /** REngineException is a generic exception that can be thrown by methods invoked on an R engine. */ 16 | public class REngineException extends Exception { 17 | /** engine associated with this exception */ 18 | protected REngine engine; 19 | 20 | /** creates an R engine exception 21 | @param engine engine associated with this exception 22 | @param msg message describing the cause */ 23 | public REngineException(REngine engine, String msg) { 24 | super(msg); 25 | this.engine = engine; 26 | } 27 | 28 | /** returns the engine associated with this exception 29 | @return engine associated with this exception */ 30 | public REngine getEngine() { return engine; } 31 | } 32 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REngineInputInterface.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** interface defining delegate methods used by {@link REngine} to forward input callbacks from R. */ 4 | public interface REngineInputInterface { 5 | /** called when R enters the read stage of the event loop. 6 | *

Important: implementations should never use a direct return! That will cause a tigh-spinning event loop. Implementation must wait for input asynchronously (e.g., declare synchonized RReadConsole and use wait()) and return only when a complete line is available for processing. 7 | * @param eng calling engine 8 | * @param prompt prompt to display in the console 9 | * @param addToHistory flag indicating whether the input is transient (false) or to be recorded in the command history (true). 10 | * @return string to be processed as console input 11 | */ 12 | public String RReadConsole(REngine eng, String prompt, int addToHistory); 13 | } 14 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REngineOutputInterface.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** interface defining delegate methods used by {@link REngine} to forward output callbacks from R. */ 4 | public interface REngineOutputInterface { 5 | /** called when R prints output to the console. 6 | * @param eng calling engine 7 | * @param text text to display in the console 8 | * @param oType output type (0=regular, 1=error/warning) 9 | */ 10 | public void RWriteConsole(REngine eng, String text, int oType); 11 | 12 | /** called when R wants to show a warning/error message box (not console-related). 13 | * @param eng calling engine 14 | * @param text text to display in the message 15 | */ 16 | public void RShowMessage(REngine eng, String text); 17 | 18 | /** called by R to flush (display) any pending console output. 19 | * @param eng calling engine */ 20 | public void RFlushConsole(REngine eng); 21 | } 22 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REngineStdOutput.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** implementation of the {@link REngineOutputInterface} which uses standard output. */ 4 | public class REngineStdOutput implements REngineCallbacks, REngineOutputInterface { 5 | public synchronized void RWriteConsole(REngine eng, String text, int oType) { 6 | ((oType == 0) ? System.out : System.err).print(text); 7 | } 8 | 9 | public void RShowMessage(REngine eng, String text) { 10 | System.err.println("*** "+text); 11 | } 12 | 13 | public void RFlushConsole(REngine eng) { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/REngineUIInterface.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | /** interface defining delegate methods used by {@link REngine} to forward user interface callbacks from R. */ 4 | public interface REngineUIInterface { 5 | /** called when the busy state of R changes - usual response is to change the shape of the cursor 6 | * @param eng calling engine 7 | * @param state busy state of R (0 = not busy) 8 | */ 9 | public void RBusyState (REngine eng, int state); 10 | 11 | /** called when R wants the user to choose a file. 12 | * @param eng calling engine 13 | * @param newFile if true then the user can specify a non-existing file to be created, otherwise an existing file must be selected. 14 | * @return full path and name of the selected file or null if the selection was cancelled. 15 | */ 16 | public String RChooseFile (REngine eng, boolean newFile); 17 | } 18 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/RFactor.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine; 2 | 3 | // REngine 4 | // Copyright (C) 2007 Simon Urbanek 5 | // --- for licensing information see LICENSE file in the original distribution --- 6 | 7 | import java.util.*; 8 | 9 | /** representation of a factor variable. In R there is no actual object 10 | type called "factor", instead it is coded as an int vector with a list 11 | attribute. The parser code of REXP converts such constructs directly into 12 | the RFactor objects and defines an own XT_FACTOR type 13 | 14 | @version $Id: RFactor.java 2841 2008-02-27 18:47:46Z urbanek $ 15 | */ 16 | public class RFactor { 17 | int ids[]; 18 | String levels[]; 19 | int index_base; 20 | 21 | /** create a new, empty factor var */ 22 | public RFactor() { ids=new int[0]; levels=new String[0]; } 23 | 24 | /** create a new factor variable, based on the supplied arrays. 25 | @param i array of IDs (inde_base..v.length+index_base-1) 26 | @param v values - cotegory names 27 | @param copy copy above vaules or just retain them 28 | @param index_base index of the first level element (1 for R factors, cannot be negtive) 29 | */ 30 | public RFactor(int[] i, String[] v, boolean copy, int index_base) { 31 | if (i==null) i = new int[0]; 32 | if (v==null) v = new String[0]; 33 | if (copy) { 34 | ids=new int[i.length]; System.arraycopy(i,0,ids,0,i.length); 35 | levels=new String[v.length]; System.arraycopy(v,0,levels,0,v.length); 36 | } else { 37 | ids=i; levels=v; 38 | } 39 | this.index_base = index_base; 40 | } 41 | 42 | /** create a new factor variable by factorizing a given string array. The levels will be created in the orer of appearance. 43 | @param c contents 44 | @param index_base base of the level index */ 45 | public RFactor(String c[], int index_base) { 46 | this.index_base = index_base; 47 | if (c == null) c = new String[0]; 48 | Vector lv = new Vector(); 49 | ids = new int[c.length]; 50 | int i = 0; 51 | while (i < c.length) { 52 | int ix = (c[i]==null)?-1:lv.indexOf(c[i]); 53 | if (ix<0 && c[i]!=null) { 54 | ix = lv.size(); 55 | lv.add(c[i]); 56 | } 57 | ids[i] = (ix<0)?REXPInteger.NA:(ix+index_base); 58 | i++; 59 | } 60 | levels = new String[lv.size()]; 61 | i = 0; 62 | while (i < levels.length) { 63 | levels[i] = (String) lv.elementAt(i); 64 | i++; 65 | } 66 | } 67 | 68 | /** same as RFactor(c, 1) */ 69 | public RFactor(String c[]) { 70 | this(c, 1); 71 | } 72 | 73 | /** same as RFactor(i,v, true, 1) */ 74 | public RFactor(int[] i, String[] v) { 75 | this(i, v, true, 1); 76 | } 77 | 78 | /** returns the level of a given case 79 | @param i case number 80 | @return name. may throw exception if out of range */ 81 | public String at(int i) { 82 | int li = ids[i] - index_base; 83 | return (li<0||li>levels.length)?null:levels[li]; 84 | } 85 | 86 | /** returns true if the data contain the given level index */ 87 | public boolean contains(int li) { 88 | int i = 0; 89 | while (i < ids.length) { 90 | if (ids[i] == li) return true; 91 | i++; 92 | } 93 | return false; 94 | } 95 | 96 | /** return true if the factor contains the given level (it is NOT the same as levelIndex==-1!) */ 97 | public boolean contains(String name) { 98 | int li = levelIndex(name); 99 | if (li<0) return false; 100 | int i = 0; 101 | while (i < ids.length) { 102 | if (ids[i] == li) return true; 103 | i++; 104 | } 105 | return false; 106 | } 107 | 108 | /** count the number of occurences of a given level index */ 109 | public int count(int levelIndex) { 110 | int i = 0; 111 | int ct = 0; 112 | while (i < ids.length) { 113 | if (ids[i] == levelIndex) ct++; 114 | i++; 115 | } 116 | return ct; 117 | } 118 | 119 | /** count the number of occurences of a given level name */ 120 | public int count(String name) { 121 | return count(levelIndex(name)); 122 | } 123 | 124 | /** return an array with level counts. */ 125 | public int[] counts() { 126 | int[] c = new int[levels.length]; 127 | int i = 0; 128 | while (i < ids.length) { 129 | final int li = ids[i] - index_base; 130 | if (li>=0 && lilevels.length)?null:levels[li]; 170 | } 171 | 172 | /** return the level index for a given case */ 173 | public int indexAt(int i) { 174 | return ids[i]; 175 | } 176 | 177 | /** return the factor as an array of strings */ 178 | public String[] asStrings() { 179 | String[] s = new String[ids.length]; 180 | int i = 0; 181 | while (i < ids.length) { 182 | s[i] = at(i); 183 | i++; 184 | } 185 | return s; 186 | } 187 | 188 | /** return the base of the levels index */ 189 | public int indexBase() { 190 | return index_base; 191 | } 192 | 193 | /** returns the number of cases */ 194 | public int size() { return ids.length; } 195 | 196 | public String toString() { 197 | return super.toString()+"["+ids.length+","+levels.length+",#"+index_base+"]"; 198 | } 199 | 200 | /** displayable representation of the factor variable 201 | public String toString() { 202 | //return "{"+((val==null)?";":("levels="+val.size()+";"))+((id==null)?"":("cases="+id.size()))+"}"; 203 | StringBuffer sb=new StringBuffer("{levels=("); 204 | if (val==null) 205 | sb.append("null"); 206 | else 207 | for (int i=0;i0)?",\"":"\""); 209 | sb.append((String)val.elementAt(i)); 210 | sb.append("\""); 211 | }; 212 | sb.append("),ids=("); 213 | if (id==null) 214 | sb.append("null"); 215 | else 216 | for (int i=0;i0) sb.append(","); 218 | sb.append((Integer)id.elementAt(i)); 219 | }; 220 | sb.append(")}"); 221 | return sb.toString(); 222 | } */ 223 | } 224 | 225 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/Rserve/Makefile: -------------------------------------------------------------------------------- 1 | RENG_SRC=$(wildcard ../*.java) 2 | RSRV_SRC=$(wildcard *.java) $(wildcard protocol/*.java) 3 | 4 | TARGETS=Rserve.jar 5 | 6 | all: $(TARGETS) 7 | 8 | JAVAC=javac 9 | JFLAGS=-encoding utf8 -source 1.4 -target 1.4 10 | 11 | ../REngine.jar: $(RENG_SRC) 12 | make -C .. REngine.jar 13 | 14 | Rserve.jar: $(RSRV_SRC) ../REngine.jar 15 | @rm -rf org 16 | $(JAVAC) -d . -cp ../REngine.jar $(RSRV_SRC) 17 | jar fc $@ org 18 | rm -rf org 19 | 20 | clean: 21 | rm -rf org *~ protocol/*~ $(TARGETS) 22 | make -C test clean 23 | 24 | test: 25 | make -C test test 26 | 27 | .PHONY: clean all test 28 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/Rserve/RFileInputStream.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine.Rserve; 2 | 3 | // JRclient library - client interface to Rserve, see http://www.rosuda.org/Rserve/ 4 | // Copyright (C) 2004 Simon Urbanek 5 | // --- for licensing information see LICENSE file in the original JRclient distribution --- 6 | 7 | import java.io.*; 8 | import org.rosuda.REngine.*; 9 | import org.rosuda.REngine.Rserve.protocol.*; 10 | 11 | /** RFileInputStream is an {@link InputStream} to transfer files 12 | from Rserve server to the client. It is used very much like 13 | a {@link FileInputStream}. Currently mark and seek is not supported. 14 | The current implementation is also "one-shot" only, that means the file 15 | can be read only once. 16 | @version $Id: RFileInputStream.java 2743 2007-05-04 16:42:17Z urbanek $ 17 | */ 18 | public class RFileInputStream extends InputStream { 19 | /** RTalk class to use for communication with the Rserve */ 20 | RTalk rt; 21 | /** set to true when {@link #close} was called. 22 | Any subsequent read requests on closed stream result in an 23 | {@link IOException} or error result */ 24 | boolean closed; 25 | /** set to true once EOF is reached - or more specifically 26 | the first time remore fread returns OK and 0 bytes */ 27 | boolean eof; 28 | 29 | /** tries to open file on the R server, using specified {@link RTalk} object 30 | and filename. Be aware that the filename has to be specified in host 31 | format (which is usually unix). In general you should not use directories 32 | since Rserve provides an own directory for every connection. Future Rserve 33 | servers may even strip all directory navigation characters for security 34 | purposes. Therefore only filenames without path specification are considered 35 | valid, the behavior in respect to absolute paths in filenames is undefined. */ 36 | RFileInputStream(RTalk rti, String fn) throws IOException { 37 | rt=rti; 38 | RPacket rp=rt.request(RTalk.CMD_openFile,fn); 39 | if (rp==null || !rp.isOk()) 40 | throw new IOException((rp==null)?"Connection to Rserve failed":("Request return code: "+rp.getStat())); 41 | closed=false; eof=false; 42 | } 43 | 44 | /** reads one byte from the file. This function should be avoided, since 45 | {@link RFileInputStream} provides no buffering. This means that each 46 | call to this function leads to a complete packet exchange between 47 | the server and the client. Use {@link #read(byte[],int,int)} instead 48 | whenever possible. In fact this function calls #read(b,0,1). 49 | @return -1 on any failure, or the acquired byte (0..255) on success */ 50 | public int read() throws IOException { 51 | byte[] b=new byte[1]; 52 | if (read(b,0,1)<1) return -1; 53 | return b[0]; 54 | } 55 | 56 | /** Reads specified number of bytes (or less) from the remote file. 57 | @param b buffer to store the read bytes 58 | @param off offset where to strat filling the buffer 59 | @param len maximal number of bytes to read 60 | @return number of bytes read or -1 if EOF reached 61 | */ 62 | public int read(byte[] b, int off, int len) throws IOException { 63 | if (closed) throw new IOException("File is not open"); 64 | if (eof) return -1; 65 | RPacket rp=rt.request(RTalk.CMD_readFile,len); 66 | if (rp==null || !rp.isOk()) 67 | throw new IOException((rp==null)?"Connection to Rserve failed":("Request return code: "+rp.getStat())); 68 | byte[] rd=rp.getCont(); 69 | if (rd==null) { 70 | eof=true; 71 | return -1; 72 | }; 73 | int i=0; 74 | while(iRFileOutputStream is an {@link OutputStream} to transfer files 17 | from the client to Rserve server. It is used very much like 18 | a {@link FileOutputStream}. Currently mark and seek is not supported. 19 | The current implementation is also "one-shot" only, that means the file 20 | can be written only once. 21 | @version $Id: RFileOutputStream.java 2743 2007-05-04 16:42:17Z urbanek $ 22 | */ 23 | 24 | public class RFileOutputStream extends OutputStream { 25 | /** RTalk class to use for communication with the Rserve */ 26 | RTalk rt; 27 | /** set to true when {@link #close} was called. 28 | Any subsequent read requests on closed stream result in an 29 | {@link IOException} or error result */ 30 | boolean closed; 31 | 32 | /** tries to create a file on the R server, using specified {@link RTalk} object 33 | and filename. Be aware that the filename has to be specified in host 34 | format (which is usually unix). In general you should not use directories 35 | since Rserve provides an own directory for every connection. Future Rserve 36 | servers may even strip all directory navigation characters for security 37 | purposes. Therefore only filenames without path specification are considered 38 | valid, the behavior in respect to absolute paths in filenames is undefined. 39 | @param rti RTalk object for communication with Rserve 40 | @param fb filename of the file to create (existing file will be overwritten) 41 | */ 42 | RFileOutputStream(RTalk rti, String fn) throws IOException { 43 | rt=rti; 44 | RPacket rp=rt.request(RTalk.CMD_createFile,fn); 45 | if (rp==null || !rp.isOk()) 46 | throw new IOException((rp==null)?"Connection to Rserve failed":("Request return code: "+rp.getStat())); 47 | closed=false; 48 | } 49 | 50 | /** writes one byte to the file. This function should be avoided, since 51 | {@link RFileOutputStream} provides no buffering. This means that each 52 | call to this function leads to a complete packet exchange between 53 | the server and the client. Use {@link #write(byte[])} instead 54 | whenever possible. In fact this function calls write(b,0,1). 55 | @param b byte to write 56 | */ 57 | public void write(int b) throws IOException { 58 | byte[] ba=new byte[1]; 59 | write(ba,0,1); 60 | } 61 | 62 | /** writes the content of b into the file. This methods is equivalent to calling write(b,0,b.length). 63 | @param b content to write 64 | */ 65 | public void write(byte b[]) throws IOException { 66 | write(b,0,b.length); 67 | } 68 | 69 | /** Writes specified number of bytes to the remote file. 70 | @param b buffer containing the bytes to write 71 | @param off offset where to start 72 | @param len number of bytes to write 73 | */ 74 | public void write(byte[] b, int off, int len) throws IOException { 75 | if (closed) throw new IOException("File is not open"); 76 | if (len<0) len=0; 77 | boolean isLarge=(len>0xfffff0); 78 | byte[] hdr=RTalk.newHdr(RTalk.DT_BYTESTREAM,len); 79 | RPacket rp=rt.request(RTalk.CMD_writeFile,hdr,b,off,len); 80 | if (rp==null || !rp.isOk()) 81 | throw new IOException((rp==null)?"Connection to Rserve failed":("Request return code: "+rp.getStat())); 82 | } 83 | 84 | /** close stream - is not related to the actual RConnection, calling 85 | close does not close the RConnection. 86 | */ 87 | public void close() throws IOException { 88 | RPacket rp=rt.request(RTalk.CMD_closeFile,(byte[])null); 89 | if (rp==null || !rp.isOk()) 90 | throw new IOException((rp==null)?"Connection to Rserve failed":("Request return code: "+rp.getStat())); 91 | closed=true; 92 | } 93 | 94 | /** currently (Rserve 0.3) there is no way to force flush on the remote side, hence this function is noop. Future versions of Rserve may support this feature though. At any rate, it is safe to call it. */ 95 | public void flush() { 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/Rserve/RSession.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine.Rserve; 2 | 3 | import org.rosuda.REngine.Rserve.protocol.RPacket; 4 | import org.rosuda.REngine.Rserve.protocol.RTalk; 5 | 6 | public class RSession implements java.io.Serializable { 7 | // serial version UID should only change if method signatures change 8 | // significantly enough that previous versions cannot be used with 9 | // current versions 10 | private static final long serialVersionUID = -7048099825974875604l; 11 | 12 | String host; 13 | int port; 14 | byte[] key; 15 | 16 | transient RPacket attachPacket=null; // response on session attach 17 | int rsrvVersion; 18 | 19 | protected RSession() { 20 | // default no-args constructor for serialization 21 | } 22 | 23 | RSession(RConnection c, RPacket p) throws RserveException { 24 | this.host=c.host; 25 | this.rsrvVersion=c.rsrvVersion; 26 | byte[] ct = p.getCont(); 27 | if (ct==null || ct.length!=32+3*4) 28 | throw new RserveException(c, "Invalid response to session detach request."); 29 | this.port = RTalk.getInt(ct, 4); 30 | this.key=new byte[32]; 31 | System.arraycopy(ct, 12, this.key, 0, 32); 32 | } 33 | 34 | /** attach/resume this session */ 35 | public RConnection attach() throws RserveException { 36 | RConnection c = new RConnection(this); 37 | attachPacket = c.rt.request(-1); 38 | return c; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/Rserve/RserveException.java: -------------------------------------------------------------------------------- 1 | // JRclient library - client interface to Rserve, see http://www.rosuda.org/Rserve/ 2 | // Copyright (C) 2004 Simon Urbanek 3 | // --- for licensing information see LICENSE file in the original JRclient distribution --- 4 | // 5 | // RserveException.java 6 | // 7 | // Created by Simon Urbanek on Mon Aug 18 2003. 8 | // 9 | // $Id: RserveException.java 3156 2009-08-12 15:35:30Z urbanek $ 10 | // 11 | 12 | package org.rosuda.REngine.Rserve; 13 | 14 | import org.rosuda.REngine.Rserve.protocol.RPacket; 15 | import org.rosuda.REngine.Rserve.protocol.RTalk; 16 | import org.rosuda.REngine.REngineException; 17 | 18 | public class RserveException extends REngineException { 19 | protected String err; 20 | protected int reqReturnCode; 21 | 22 | public String getRequestErrorDescription() { 23 | return getRequestErrorDescription(reqReturnCode); 24 | } 25 | 26 | public String getRequestErrorDescription(int code) { 27 | switch(code) { 28 | case 0: return "no error"; 29 | case 2: return "R parser: input incomplete"; 30 | case 3: return "R parser: syntax error"; 31 | case RTalk.ERR_auth_failed: return "authorization failed"; 32 | case RTalk.ERR_conn_broken: return "connection broken"; 33 | case RTalk.ERR_inv_cmd: return "invalid command"; 34 | case RTalk.ERR_inv_par: return "invalid parameter"; 35 | case RTalk.ERR_IOerror: return "I/O error on the server"; 36 | case RTalk.ERR_not_open: return "connection is not open"; 37 | case RTalk.ERR_access_denied: return "access denied (local to the server)"; 38 | case RTalk.ERR_unsupported_cmd: return "unsupported command"; 39 | case RTalk.ERR_unknown_cmd: return "unknown command"; 40 | case RTalk.ERR_data_overflow: return "data overflow, incoming data too big"; 41 | case RTalk.ERR_object_too_big: return "evaluation successful, but returned object is too big to transport"; 42 | case RTalk.ERR_out_of_mem: return "FATAL: Rserve ran out of memory, closing connection"; 43 | case RTalk.ERR_session_busy: return "session is busy"; 44 | case RTalk.ERR_detach_failed: return "session detach failed"; 45 | case RTalk.ERR_ctrl_closed: return "control pipe to master process is closed/broken"; 46 | } 47 | return "error code: "+code; 48 | } 49 | 50 | public String getMessage() { 51 | return super.getMessage()+((reqReturnCode!=-1)?", request status: "+getRequestErrorDescription():""); 52 | } 53 | 54 | public RserveException(RConnection c, String msg) { 55 | this(c,msg,-1); 56 | } 57 | 58 | public RserveException(RConnection c, String msg, int requestReturnCode) { 59 | super(c, msg); 60 | reqReturnCode=requestReturnCode; 61 | if (c!=null) c.lastError=getMessage(); 62 | } 63 | 64 | public RserveException(RConnection c, String msg, RPacket p) { 65 | this(c, msg, (p==null)?-1:p.getStat()); 66 | } 67 | 68 | public int getRequestReturnCode() { 69 | return reqReturnCode; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/Rserve/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * REngine-based interface to Rserve 3 | */ 4 | package org.rosuda.REngine.Rserve ; 5 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/Rserve/protocol/RPacket.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.REngine.Rserve.protocol; 2 | 3 | // JRclient library - client interface to Rserve, see http://www.rosuda.org/Rserve/ 4 | // Copyright (C) 2004 Simon Urbanek 5 | // --- for licensing information see LICENSE file in the original JRclient distribution --- 6 | 7 | /** small class encapsulating packets from/to Rserv 8 | @version $Id: RPacket.java 2743 2007-05-04 16:42:17Z urbanek $ 9 | */ 10 | public class RPacket { 11 | int cmd; 12 | byte[] cont; 13 | 14 | /** construct new packet 15 | @param Rcmd command 16 | @param Rcont content */ 17 | public RPacket(int Rcmd, byte[] Rcont) { 18 | cmd=Rcmd; cont=Rcont; 19 | } 20 | 21 | /** get command 22 | @return command */ 23 | public int getCmd() { return cmd; } 24 | 25 | /** check last response for RESP_OK 26 | @return true if last response was OK */ 27 | public boolean isOk() { return ((cmd&15)==1); } 28 | 29 | /** check last response for RESP_ERR 30 | @return true if last response was ERROR */ 31 | public boolean isError() { return ((cmd&15)==2); } 32 | 33 | /** get status code of last response 34 | @return status code returned on last response */ 35 | public int getStat() { return ((cmd>>24)&127); } 36 | 37 | /** get content 38 | @return inner package content */ 39 | public byte[] getCont() { return cont; } 40 | 41 | public String toString() { return "RPacket[cmd="+cmd+",len="+((cont==null)?"":(""+cont.length))+"]"; } 42 | } 43 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/Rserve/test/Makefile: -------------------------------------------------------------------------------- 1 | JAVA=java 2 | JAVAC=javac 3 | JFLAGS+=-encoding utf8 -source 1.4 -target 1.4 4 | 5 | all: test PlotDemo.class StartRserve.class 6 | 7 | ../Rserve.jar: ../../REngine.jar 8 | $(MAKE) -C .. Rserve.jar 9 | 10 | ../../REngine.jar: 11 | $(MAKE) -C ../.. REngine.jar 12 | 13 | test: test.class ../Rserve.jar ../../REngine.jar 14 | $(JAVA) -cp ../Rserve.jar:../../REngine.jar:. test 15 | 16 | test.class: test.java ../Rserve.jar ../../REngine.jar 17 | $(JAVAC) $(JFLAGS) -d . -cp ../Rserve.jar:../../REngine.jar:. test.java 18 | 19 | PlotDemo.class: PlotDemo.java ../Rserve.jar ../../REngine.jar 20 | $(JAVAC) $(JFLAGS) -d . -cp ../Rserve.jar:../../REngine.jar:. $< 21 | 22 | PlotDemo: PlotDemo.class ../Rserve.jar ../../REngine.jar 23 | $(JAVA) -cp ../Rserve.jar:../../REngine.jar:. $@ 24 | 25 | jt: jt.class ../Rserve.jar ../../REngine.jar 26 | $(JAVA) -cp ../Rserve.jar:../../REngine.jar:. $@ 27 | 28 | jt.class: jt.java ../Rserve.jar ../../REngine.jar 29 | $(JAVAC) $(JFLAGS) -d . -cp ../Rserve.jar:../../REngine.jar:. jt.java 30 | 31 | StartRserve.class: StartRserve.java ../Rserve.jar ../../REngine.jar 32 | $(JAVAC) $(JFLAGS) -d . -cp ../Rserve.jar:../../REngine.jar:. StartRserve.java 33 | 34 | clean: 35 | rm -rf org *~ *.class 36 | 37 | .PHONY: test all clean 38 | 39 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/Rserve/test/PlotDemo.java: -------------------------------------------------------------------------------- 1 | // 2 | // PlotDemo demo - REngine and graphics 3 | // 4 | // $Id: PlotDemo.java 2767 2007-05-24 16:49:25Z urbanek $ 5 | // 6 | 7 | import java.io.*; 8 | import java.util.*; 9 | import java.awt.*; 10 | import java.awt.event.*; 11 | 12 | import org.rosuda.REngine.*; 13 | import org.rosuda.REngine.Rserve.*; 14 | 15 | /** A demonstration of the use of Rserver and graphics devices to create graphics in R, pull them into Java and display them. It is a really simple demo. */ 16 | public class PlotDemo extends Canvas { 17 | public static void main(String args[]) { 18 | try { 19 | String device = "jpeg"; // device we'll call (this would work with pretty much any bitmap device) 20 | 21 | // connect to Rserve (if the user specified a server at the command line, use it, otherwise connect locally) 22 | RConnection c = new RConnection((args.length>0)?args[0]:"127.0.0.1"); 23 | 24 | // if Cairo is installed, we can get much nicer graphics, so try to load it 25 | if (c.parseAndEval("suppressWarnings(require('Cairo',quietly=TRUE))").asInteger()>0) 26 | device="CairoJPEG"; // great, we can use Cairo device 27 | else 28 | System.out.println("(consider installing Cairo package for better bitmap output)"); 29 | 30 | // we are careful here - not all R binaries support jpeg 31 | // so we rather capture any failures 32 | REXP xp = c.parseAndEval("try("+device+"('test.jpg',quality=90))"); 33 | 34 | if (xp.inherits("try-error")) { // if the result is of the class try-error then there was a problem 35 | System.err.println("Can't open "+device+" graphics device:\n"+xp.asString()); 36 | // this is analogous to 'warnings', but for us it's sufficient to get just the 1st warning 37 | REXP w = c.eval("if (exists('last.warning') && length(last.warning)>0) names(last.warning)[1] else 0"); 38 | if (w.isString()) System.err.println(w.asString()); 39 | return; 40 | } 41 | 42 | // ok, so the device should be fine - let's plot - replace this by any plotting code you desire ... 43 | c.parseAndEval("data(iris); attach(iris); plot(Sepal.Length, Petal.Length, col=unclass(Species)); dev.off()"); 44 | 45 | // There is no I/O API in REngine because it's actually more efficient to use R for this 46 | // we limit the file size to 1MB which should be sufficient and we delete the file as well 47 | xp = c.parseAndEval("r=readBin('test.jpg','raw',1024*1024); unlink('test.jpg'); r"); 48 | 49 | // now this is pretty boring AWT stuff - create an image from the data and display it ... 50 | Image img = Toolkit.getDefaultToolkit().createImage(xp.asBytes()); 51 | 52 | Frame f = new Frame("Test image"); 53 | f.add(new PlotDemo(img)); 54 | f.addWindowListener(new WindowAdapter() { // just so we can close the window 55 | public void windowClosing(WindowEvent e) { System.exit(0); } 56 | }); 57 | f.pack(); 58 | f.setVisible(true); 59 | 60 | // close RConnection, we're done 61 | c.close(); 62 | } catch (RserveException rse) { // RserveException (transport layer - e.g. Rserve is not running) 63 | System.out.println(rse); 64 | } catch (REXPMismatchException mme) { // REXP mismatch exception (we got something we didn't think we get) 65 | System.out.println(mme); 66 | mme.printStackTrace(); 67 | } catch(Exception e) { // something else 68 | System.out.println("Something went wrong, but it's not the Rserve: " 69 | +e.getMessage()); 70 | e.printStackTrace(); 71 | } 72 | } 73 | 74 | Image img; 75 | 76 | public PlotDemo(Image img) { 77 | this.img=img; 78 | MediaTracker mediaTracker = new MediaTracker(this); 79 | mediaTracker.addImage(img, 0); 80 | try { 81 | mediaTracker.waitForID(0); 82 | } catch (InterruptedException ie) { 83 | System.err.println(ie); 84 | System.exit(1); 85 | } 86 | setSize(img.getWidth(null), img.getHeight(null)); 87 | } 88 | 89 | public void paint(Graphics g) { 90 | g.drawImage(img, 0, 0, null); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/Rserve/test/jt.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import org.rosuda.REngine.*; 3 | import org.rosuda.REngine.Rserve.*; 4 | 5 | public class jt { 6 | public static void main(String[] args) { 7 | try { 8 | RConnection c = new RConnection((args.length>0)?args[0]:"127.0.0.1"); 9 | 10 | BufferedReader ir=new BufferedReader(new InputStreamReader(System.in)); 11 | String s=null; 12 | System.out.print("> "); 13 | while ((s=ir.readLine()).length() > 0) { 14 | if (s.equals("shutdown")) { 15 | System.out.println("Sending shutdown request"); 16 | c.shutdown(); 17 | System.out.println("Shutdown successful. Quitting console."); 18 | return; 19 | } else { 20 | REXP rx = c.parseAndEval(s); 21 | System.out.println("result(debug): "+rx.toDebugString()); 22 | } 23 | System.out.print("> "); 24 | } 25 | 26 | } catch (RserveException rse) { 27 | System.out.println(rse); 28 | /* } catch (REXPMismatchException mme) { 29 | System.out.println(mme); 30 | mme.printStackTrace(); */ 31 | } catch (Exception e) { 32 | e.printStackTrace(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Rserve/src/client/java-new/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * High level java interface to R 3 | */ 4 | package org.rosuda.REngine ; 5 | 6 | -------------------------------------------------------------------------------- /Rserve/src/client/java-old/LICENSE: -------------------------------------------------------------------------------- 1 | JRclient - Java implementation of a client for Rserve 2 | Copyright (C) 2004 Simon Urbanek 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | -------------------------------------------------------------------------------- /Rserve/src/client/java-old/Makefile: -------------------------------------------------------------------------------- 1 | all: JRclient.jar 2 | make -C examples 3 | 4 | JRclient.jar: *.java 5 | rm -rf org 6 | javac -d . *.java 7 | jar fvc JRclient.jar org 8 | rm -rf org 9 | 10 | doc: 11 | rm -rf JavaDoc 12 | mkdir -p JavaDoc 13 | javadoc -d JavaDoc -author -version -breakiterator -link http://java.sun.com/products/jdk/1.2/docs/api *.java 14 | 15 | clean: 16 | rm -rf JRclient.jar org JavaDoc *~ 17 | make -C examples clean 18 | 19 | test: 20 | make -C examples test 21 | -------------------------------------------------------------------------------- /Rserve/src/client/java-old/RBool.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.JRclient; 2 | 3 | // JRclient library - client interface to Rserve, see http://www.rosuda.org/Rserve/ 4 | // Copyright (C) 2004 Simon Urbanek 5 | // --- for licensing information see LICENSE file in the original JRclient distribution --- 6 | 7 | /** Implementation of tri-state logical data type in R. 8 | The three states are TRUE, FALSE and NA. To obtain truly boolean 9 | value, you'll need to use {@link #isTRUE} or {@link #isFALSE} since there is 10 | no canonical representation of RBool in boolean 11 | 12 | @version $Id: RBool.java 1330 2005-01-24 18:25:42Z urbaneks $ 13 | */ 14 | public class RBool extends Object { 15 | int val; 16 | 17 | public RBool(boolean b) { 18 | val=(b)?1:0; 19 | }; 20 | public RBool(RBool r) { 21 | val=r.val; 22 | }; 23 | public RBool(int i) { /* 0=FALSE, 2=NA, anything else = TRUE */ 24 | val=(i==0||i==2)?i:1; 25 | }; 26 | 27 | public boolean isNA() { return (val==2); }; 28 | public boolean isTRUE() { return (val==1); }; 29 | public boolean isFALSE() { return (val==0); }; 30 | 31 | public String toString() { return (val==0)?"FALSE":((val==2)?"NA":"TRUE"); }; 32 | } 33 | -------------------------------------------------------------------------------- /Rserve/src/client/java-old/RFactor.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.JRclient; 2 | 3 | // JRclient library - client interface to Rserve, see http://www.rosuda.org/Rserve/ 4 | // Copyright (C) 2004 Simon Urbanek 5 | // --- for licensing information see LICENSE file in the original JRclient distribution --- 6 | 7 | import java.util.*; 8 | 9 | /** representation of a factor variable. In R there is no actual xpression 10 | type called "factor", instead it is coded as an int vector with a list 11 | attribute. The parser code of REXP converts such constructs directly into 12 | the RFactor objects and defines an own XT_FACTOR type 13 | 14 | @version $Id: RFactor.java 2746 2007-05-10 17:14:14Z urbanek $ 15 | */ 16 | public class RFactor extends Object { 17 | /** IDs (content: Integer) each entry corresponds to a case, ID specifies the category */ 18 | Vector id; 19 | /** values (content: String), ergo category names */ 20 | Vector val; 21 | 22 | /** create a new, empty factor var */ 23 | public RFactor() { id=new Vector(); val=new Vector(); } 24 | 25 | /** create a new factor variable, based on the supplied arrays. 26 | @param i array if IDs (0..v.length-1) 27 | @param v values - cotegory names */ 28 | public RFactor(int[] i, String[] v) { 29 | id=new Vector(); val=new Vector(); 30 | int j; 31 | if (i!=null && i.length>0) 32 | for(j=0;j0) 35 | for(j=0;j0) 47 | for(j=0;j0) 50 | for(j=0;j=id.size()) return null; 72 | return (String)val.elementAt(((Integer)id.elementAt(i)).intValue()); 73 | } 74 | 75 | /** returns the number of caes */ 76 | public int size() { return id.size(); } 77 | 78 | /** displayable representation of the factor variable */ 79 | public String toString() { 80 | //return "{"+((val==null)?";":("levels="+val.size()+";"))+((id==null)?"":("cases="+id.size()))+"}"; 81 | StringBuffer sb=new StringBuffer("{levels=("); 82 | if (val==null) 83 | sb.append("null"); 84 | else 85 | for (int i=0;i0)?",\"":"\""); 87 | sb.append((String)val.elementAt(i)); 88 | sb.append("\""); 89 | }; 90 | sb.append("),ids=("); 91 | if (id==null) 92 | sb.append("null"); 93 | else 94 | for (int i=0;i0) sb.append(","); 96 | sb.append((Integer)id.elementAt(i)); 97 | }; 98 | sb.append(")}"); 99 | return sb.toString(); 100 | } 101 | } 102 | 103 | -------------------------------------------------------------------------------- /Rserve/src/client/java-old/RFileInputStream.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.JRclient; 2 | 3 | // JRclient library - client interface to Rserve, see http://www.rosuda.org/Rserve/ 4 | // Copyright (C) 2004 Simon Urbanek 5 | // --- for licensing information see LICENSE file in the original JRclient distribution --- 6 | 7 | import java.io.*; 8 | 9 | /** RFileInputStream is an {@link InputStream} to transfer files 10 | from Rserve server to the client. It is used very much like 11 | a {@link FileInputStream}. Currently mark and seek is not supported. 12 | The current implementation is also "one-shot" only, that means the file 13 | can be read only once. 14 | @version $Id: RFileInputStream.java 1330 2005-01-24 18:25:42Z urbaneks $ 15 | */ 16 | public class RFileInputStream extends InputStream { 17 | /** Rtalk class to use for communication with the Rserve */ 18 | Rtalk rt; 19 | /** set to true when {@link #close} was called. 20 | Any subsequent read requests on closed stream result in an 21 | {@link IOException} or error result */ 22 | boolean closed; 23 | /** set to true once EOF is reached - or more specifically 24 | the first time remore fread returns OK and 0 bytes */ 25 | boolean eof; 26 | 27 | /** tries to open file on the R server, using specified {@link Rtalk} object 28 | and filename. Be aware that the filename has to be specified in host 29 | format (which is usually unix). In general you should not use directories 30 | since Rserve provides an own directory for every connection. Future Rserve 31 | servers may even strip all directory navigation characters for security 32 | purposes. Therefore only filenames without path specification are considered 33 | valid, the behavior in respect to absolute paths in filenames is undefined. */ 34 | RFileInputStream(Rtalk rti, String fn) throws IOException { 35 | rt=rti; 36 | Rpacket rp=rt.request(Rtalk.CMD_openFile,fn); 37 | if (rp==null || !rp.isOk()) 38 | throw new IOException((rp==null)?"Connection to Rserve failed":("Request return code: "+rp.getStat())); 39 | closed=false; eof=false; 40 | } 41 | 42 | /** reads one byte from the file. This function should be avoided, since 43 | {@link RFileInputStream} provides no buffering. This means that each 44 | call to this function leads to a complete packet exchange between 45 | the server and the client. Use {@link #read(byte[],int,int)} instead 46 | whenever possible. In fact this function calls #read(b,0,1). 47 | @return -1 on any failure, or the acquired byte (0..255) on success */ 48 | public int read() throws IOException { 49 | byte[] b=new byte[1]; 50 | if (read(b,0,1)<1) return -1; 51 | return b[0]; 52 | } 53 | 54 | /** Reads specified number of bytes (or less) from the remote file. 55 | @param b buffer to store the read bytes 56 | @param off offset where to strat filling the buffer 57 | @param len maximal number of bytes to read 58 | @return number of bytes read or -1 if EOF reached 59 | */ 60 | public int read(byte[] b, int off, int len) throws IOException { 61 | if (closed) throw new IOException("File is not open"); 62 | if (eof) return -1; 63 | Rpacket rp=rt.request(Rtalk.CMD_readFile,len); 64 | if (rp==null || !rp.isOk()) 65 | throw new IOException((rp==null)?"Connection to Rserve failed":("Request return code: "+rp.getStat())); 66 | byte[] rd=rp.getCont(); 67 | if (rd==null) { 68 | eof=true; 69 | return -1; 70 | }; 71 | int i=0; 72 | while(iRFileOutputStream is an {@link OutputStream} to transfer files 15 | from the client to Rserve server. It is used very much like 16 | a {@link FileOutputStream}. Currently mark and seek is not supported. 17 | The current implementation is also "one-shot" only, that means the file 18 | can be written only once. 19 | @version $Id: RFileOutputStream.java 1330 2005-01-24 18:25:42Z urbaneks $ 20 | */ 21 | 22 | public class RFileOutputStream extends OutputStream { 23 | /** Rtalk class to use for communication with the Rserve */ 24 | Rtalk rt; 25 | /** set to true when {@link #close} was called. 26 | Any subsequent read requests on closed stream result in an 27 | {@link IOException} or error result */ 28 | boolean closed; 29 | 30 | /** tries to create a file on the R server, using specified {@link Rtalk} object 31 | and filename. Be aware that the filename has to be specified in host 32 | format (which is usually unix). In general you should not use directories 33 | since Rserve provides an own directory for every connection. Future Rserve 34 | servers may even strip all directory navigation characters for security 35 | purposes. Therefore only filenames without path specification are considered 36 | valid, the behavior in respect to absolute paths in filenames is undefined. 37 | @param rti RTalk object for communication with Rserve 38 | @param fb filename of the file to create (existing file will be overwritten) 39 | */ 40 | RFileOutputStream(Rtalk rti, String fn) throws IOException { 41 | rt=rti; 42 | Rpacket rp=rt.request(Rtalk.CMD_createFile,fn); 43 | if (rp==null || !rp.isOk()) 44 | throw new IOException((rp==null)?"Connection to Rserve failed":("Request return code: "+rp.getStat())); 45 | closed=false; 46 | } 47 | 48 | /** writes one byte to the file. This function should be avoided, since 49 | {@link RFileOutputStream} provides no buffering. This means that each 50 | call to this function leads to a complete packet exchange between 51 | the server and the client. Use {@link #write(byte[])} instead 52 | whenever possible. In fact this function calls write(b,0,1). 53 | @param b byte to write 54 | */ 55 | public void write(int b) throws IOException { 56 | byte[] ba=new byte[1]; 57 | write(ba,0,1); 58 | } 59 | 60 | /** writes the content of b into the file. This methods is equivalent to calling write(b,0,b.length). 61 | @param b content to write 62 | */ 63 | public void write(byte b[]) throws IOException { 64 | write(b,0,b.length); 65 | } 66 | 67 | /** Writes specified number of bytes to the remote file. 68 | @param b buffer containing the bytes to write 69 | @param off offset where to start 70 | @param len number of bytes to write 71 | */ 72 | public void write(byte[] b, int off, int len) throws IOException { 73 | if (closed) throw new IOException("File is not open"); 74 | if (len<0) len=0; 75 | boolean isLarge=(len>0xfffff0); 76 | byte[] hdr=Rtalk.newHdr(Rtalk.DT_BYTESTREAM,len); 77 | Rpacket rp=rt.request(Rtalk.CMD_writeFile,hdr,b,off,len); 78 | if (rp==null || !rp.isOk()) 79 | throw new IOException((rp==null)?"Connection to Rserve failed":("Request return code: "+rp.getStat())); 80 | } 81 | 82 | /** close stream - is not related to the actual Rconnection, calling 83 | close does not close the Rconnection. 84 | */ 85 | public void close() throws IOException { 86 | Rpacket rp=rt.request(Rtalk.CMD_closeFile,(byte[])null); 87 | if (rp==null || !rp.isOk()) 88 | throw new IOException((rp==null)?"Connection to Rserve failed":("Request return code: "+rp.getStat())); 89 | closed=true; 90 | } 91 | 92 | /** currently (Rserve 0.3) there is no way to force flush on the remote side, hence this function is noop. Future versions of Rserve may support this feature though. At any rate, it is safe to call it. */ 93 | public void flush() { 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Rserve/src/client/java-old/RSession.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.JRclient; 2 | 3 | public class RSession implements java.io.Serializable { 4 | // serial version UID should only change if method signatures change 5 | // significantly enough that previous versions cannot be used with 6 | // current versions 7 | private static final long serialVersionUID = -7048099825974875604l; 8 | 9 | String host; 10 | int port; 11 | byte[] key; 12 | 13 | transient Rpacket attachPacket=null; // response on session attach 14 | int rsrvVersion; 15 | 16 | protected RSession() { 17 | // default no-args constructor for serialization 18 | } 19 | 20 | RSession(Rconnection c, Rpacket p) throws RSrvException { 21 | this.host=c.host; 22 | this.rsrvVersion=c.rsrvVersion; 23 | byte[] ct = p.getCont(); 24 | if (ct==null || ct.length!=32+3*4) 25 | throw new RSrvException(c, "Invalid response to session detach request."); 26 | this.port = Rtalk.getInt(ct, 4); 27 | this.key=new byte[32]; 28 | System.arraycopy(ct, 12, this.key, 0, 32); 29 | } 30 | 31 | /** attach/resume this session */ 32 | public Rconnection attach() throws RSrvException { 33 | Rconnection c = new Rconnection(this); 34 | attachPacket = c.rt.request(-1); 35 | return c; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Rserve/src/client/java-old/RSrvException.java: -------------------------------------------------------------------------------- 1 | // JRclient library - client interface to Rserve, see http://www.rosuda.org/Rserve/ 2 | // Copyright (C) 2004 Simon Urbanek 3 | // --- for licensing information see LICENSE file in the original JRclient distribution --- 4 | // 5 | // RSrvException.java 6 | // 7 | // Created by Simon Urbanek on Mon Aug 18 2003. 8 | // 9 | // $Id: RSrvException.java 1949 2006-02-10 17:57:54Z urbaneks $ 10 | // 11 | 12 | package org.rosuda.JRclient; 13 | 14 | public class RSrvException extends Exception { 15 | protected Rconnection conn; 16 | protected String err; 17 | protected int reqReturnCode; 18 | 19 | public String getRequestErrorDescription() { 20 | return getRequestErrorDescription(reqReturnCode); 21 | } 22 | 23 | public String getRequestErrorDescription(int code) { 24 | switch(code) { 25 | case 0: return "no error"; 26 | case 2: return "R parser: input incomplete"; 27 | case 3: return "R parser: syntax error"; 28 | case Rtalk.ERR_auth_failed: return "authorization failed"; 29 | case Rtalk.ERR_conn_broken: return "connection broken"; 30 | case Rtalk.ERR_inv_cmd: return "invalid command"; 31 | case Rtalk.ERR_inv_par: return "invalid parameter"; 32 | case Rtalk.ERR_IOerror: return "I/O error on the server"; 33 | case Rtalk.ERR_not_open: return "connection is not open"; 34 | case Rtalk.ERR_access_denied: return "access denied (local to the server)"; 35 | case Rtalk.ERR_unsupported_cmd: return "unsupported command"; 36 | case Rtalk.ERR_unknown_cmd: return "unknown command"; 37 | case Rtalk.ERR_data_overflow: return "data overflow, incoming data too big"; 38 | case Rtalk.ERR_object_too_big: return "evaluation successful, but returned object is too big to transport"; 39 | case Rtalk.ERR_out_of_mem: return "FATAL: Rserve ran out of memory, closing connection"; 40 | case Rtalk.ERR_session_busy: return "session is busy"; 41 | case Rtalk.ERR_detach_failed: return "session detach failed"; 42 | } 43 | return "error code: "+code; 44 | } 45 | 46 | public String getMessage() { 47 | return super.getMessage()+((reqReturnCode!=-1)?", request status: "+getRequestErrorDescription():""); 48 | } 49 | 50 | public RSrvException(Rconnection c, String msg) { 51 | this(c,msg,-1); 52 | } 53 | 54 | public RSrvException(Rconnection c, String msg, int requestReturnCode) { 55 | super(msg); 56 | conn=c; reqReturnCode=requestReturnCode; 57 | if (c!=null) c.lastError=getMessage(); 58 | } 59 | 60 | public RSrvException(Rconnection c, String msg, Rpacket p) { 61 | this(c, msg, (p==null)?-1:p.getStat()); 62 | } 63 | 64 | public int getRequestReturnCode() { 65 | return reqReturnCode; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Rserve/src/client/java-old/Rpacket.java: -------------------------------------------------------------------------------- 1 | package org.rosuda.JRclient; 2 | 3 | // JRclient library - client interface to Rserve, see http://www.rosuda.org/Rserve/ 4 | // Copyright (C) 2004 Simon Urbanek 5 | // --- for licensing information see LICENSE file in the original JRclient distribution --- 6 | 7 | /** small class encapsulating packets from/to Rserv 8 | @version $Id: Rpacket.java 2071 2006-03-09 22:07:21Z dmao $ 9 | */ 10 | public class Rpacket { 11 | int cmd; 12 | byte[] cont; 13 | 14 | /** construct new packet 15 | @param Rcmd command 16 | @param Rcont content */ 17 | public Rpacket(int Rcmd, byte[] Rcont) { 18 | cmd=Rcmd; cont=Rcont; 19 | } 20 | 21 | /** get command 22 | @return command */ 23 | public int getCmd() { return cmd; } 24 | 25 | /** check last response for RESP_OK 26 | @return true if last response was OK */ 27 | public boolean isOk() { return ((cmd&15)==1); } 28 | 29 | /** check last response for RESP_ERR 30 | @return true if last response was ERROR */ 31 | public boolean isError() { return ((cmd&15)==2); } 32 | 33 | /** get status code of last response 34 | @return status code returned on last response */ 35 | public int getStat() { return ((cmd>>24)&127); } 36 | 37 | /** get content 38 | @return inner package content */ 39 | public byte[] getCont() { return cont; } 40 | 41 | public String toString() { return "Rpacket[cmd="+cmd+",len="+((cont==null)?"":(""+cont.length))+"]"; } 42 | } 43 | -------------------------------------------------------------------------------- /Rserve/src/client/java-old/examples/Makefile: -------------------------------------------------------------------------------- 1 | JAVA_PREFIX=java 2 | JAVAR=$(JAVA_PREFIX) 3 | JAVAC=$(JAVA_PREFIX)c $(JFLAGS) 4 | JRC_JAR=../JRclient.jar 5 | 6 | all: jt.class t.class PlotDemo.class 7 | 8 | jt.class: jt.java $(JRC_JAR) 9 | $(JAVAC) -classpath $(JRC_JAR) $< 10 | 11 | t.class: t.java $(JRC_JAR) 12 | $(JAVAC) -classpath $(JRC_JAR) $< 13 | 14 | PlotDemo.class: PlotDemo.java $(JRC_JAR) 15 | $(JAVAC) -classpath $(JRC_JAR) $< 16 | 17 | run: jt.class $(JRC_JAR) 18 | $(JAVAR) -cp $(JRC_JAR):. jt 19 | 20 | test: t.class $(JRC_JAR) 21 | $(JAVAR) -cp $(JRC_JAR):. t 22 | 23 | clean: 24 | rm -rf *.class *~ 25 | -------------------------------------------------------------------------------- /Rserve/src/client/java-old/examples/PlotDemo.java: -------------------------------------------------------------------------------- 1 | // 2 | // JRclient demo - Rserve and graphics 3 | // 4 | // $Id: PlotDemo.java 1088 2004-08-17 16:50:00Z urbaneks $ 5 | // 6 | 7 | import org.rosuda.JRclient.*; 8 | import java.io.*; 9 | import java.util.*; 10 | import java.awt.*; 11 | import java.awt.event.*; 12 | 13 | // this is just a quick-and-dirty demo how to create graphics output in R and display it on the client side. It's not very efficient, but it's remote-capable. It demonstrates the use of file transfer and some error recovery techniques. Everything else is just AWT and I/O stuff 14 | 15 | public class PlotDemo extends Canvas { 16 | public static void main(String args[]) { 17 | try { 18 | Rconnection c=new Rconnection((args.length>0)?args[0]:"127.0.0.1"); 19 | 20 | // just some demo data 21 | c.voidEval("data(iris); attach(iris)"); 22 | 23 | // we are careful here - not all R binaries support jpeg 24 | // so we rather capture any failures 25 | REXP xp=c.eval("try(jpeg(\"test.jpg\"))"); 26 | 27 | if (xp.asString()!=null) { // if there's a string then we have a problem, R sent an error 28 | System.out.println("Can't open jpeg graphics device:\n"+xp.asString()); 29 | // this is analogous to 'warnings', but for us it's sufficient to get just the 1st warning 30 | REXP w=c.eval("if (exists(\"last.warning\") && length(last.warning)>0) names(last.warning)[1] else 0"); 31 | if (w.asString()!=null) System.out.println(w.asString()); 32 | return; 33 | } 34 | 35 | // ok, so the device should be fine - let's plot 36 | c.voidEval("plot(Sepal.Length, Petal.Length, col=unclass(Species))"); 37 | c.voidEval("dev.off()"); 38 | 39 | // the file should be ready now, so let's read (ok this isn't pretty, but hey, this ain't no beauty contest *grin* =) 40 | // we read in chunks of bufSize (64k by default) and store the resulting byte arrays in a vector 41 | // ... just in case the file gets really big ... 42 | // we don't know the size in advance, because it's just a stream. 43 | // also we can't rewind it, so we have to store it piece-by-piece 44 | RFileInputStream is=c.openFile("test.jpg"); 45 | Vector buffers=new Vector(); 46 | int bufSize=65536; 47 | byte[] buf=new byte[bufSize]; 48 | int imgLength=0; 49 | int n=0; 50 | while (true) { 51 | n=is.read(buf); 52 | if (n==bufSize) { 53 | buffers.addElement(buf); 54 | buf=new byte[bufSize]; 55 | } 56 | if (n>0) imgLength+=n; 57 | if (n0) System.arraycopy(buf,0,imgCode,imgPos,n); 74 | 75 | // ... and close the file ... and remove it - we have what we need :) 76 | is.close(); 77 | c.removeFile("test.jpg"); 78 | 79 | // now this is pretty boring AWT stuff, nothing to do with R ... 80 | Image img = Toolkit.getDefaultToolkit().createImage(imgCode); 81 | 82 | Frame f = new Frame("Test image"); 83 | f.add(new PlotDemo(img)); 84 | f.addWindowListener(new WindowAdapter() { // just do we can close the window 85 | public void windowClosing(WindowEvent e) { System.exit(0); } 86 | }); 87 | f.pack(); 88 | f.setVisible(true); 89 | 90 | // close Rconnection, we're done 91 | c.close(); 92 | } catch(RSrvException rse) { 93 | System.out.println("Rserve exception: "+rse.getMessage()); 94 | } catch(Exception e) { 95 | System.out.println("Something went wrong, but it's not the Rserve: " 96 | +e.getMessage()); 97 | e.printStackTrace(); 98 | } 99 | } 100 | 101 | Image img; 102 | 103 | public PlotDemo(Image img) { 104 | this.img=img; 105 | MediaTracker mediaTracker = new MediaTracker(this); 106 | mediaTracker.addImage(img, 0); 107 | try { 108 | mediaTracker.waitForID(0); 109 | } catch (InterruptedException ie) { 110 | System.err.println(ie); 111 | System.exit(1); 112 | } 113 | setSize(img.getWidth(null), img.getHeight(null)); 114 | } 115 | 116 | public void paint(Graphics g) { 117 | g.drawImage(img, 0, 0, null); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /Rserve/src/client/java-old/examples/jt.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import org.rosuda.JRclient.*; 3 | 4 | /** sample class demonstrating the use of the Java interface to Rserv.
5 | it is basically a primitive R console/object inspector 6 | @version $Id: jt.java 687 2004-02-01 20:40:48Z urbaneks $ 7 | */ 8 | public class jt { 9 | public static void main(String[] arg) { 10 | try { 11 | Rconnection c = new Rconnection((arg.length>0)?arg[0]:"127.0.0.1"); // make new connecton 12 | System.out.println("Server vesion: "+c.getServerVersion()); 13 | if (c.needLogin()) { // if server requires authentication, send one 14 | System.out.println("authentication required."); 15 | c.login("guest","guest"); 16 | } 17 | 18 | BufferedReader ir=new BufferedReader(new InputStreamReader(System.in)); 19 | String s=null; 20 | System.out.print("> "); 21 | while ((s=ir.readLine()).length()>0) { 22 | // this is just a quick hack to test assignments 23 | // if the user types: #symbol value 24 | // then symbol<-value is performed 25 | // if no value is specified then an array of integers is assigned 26 | if (s.equals("shutdown")) { 27 | System.out.println("Sending shutdown request"); 28 | c.shutdown(); 29 | System.out.println("Shutdown successful. Quitting console."); 30 | return; 31 | } else 32 | if (s.length()>1 && s.charAt(0)=='#') { 33 | s=s.substring(1); 34 | int i=s.indexOf(' '); 35 | if (i<1) { 36 | int ti[]=new int[16]; 37 | int j=0; while (j<16) { ti[j]=(j==0)?1:ti[j-1]*j; j++; }; 38 | REXP r=new REXP(REXP.XT_ARRAY_INT,ti); 39 | //double ti[]=new double[16]; 40 | //int j=0; while (j<16) { ti[j]=((double)j)/2; j++; }; 41 | //REXP r=new REXP(REXP.XT_ARRAY_DOUBLE,ti); 42 | c.assign(s,r); 43 | System.out.println("assign(\""+s+"\","+r+") OK"); 44 | } else { 45 | c.assign(s.substring(0,i),s.substring(i+1)); 46 | System.out.println("assign(\""+s+"\") OK"); 47 | } 48 | } else { 49 | REXP rx=c.eval(s); 50 | System.out.println("exp: "+rx.toString()); 51 | } 52 | System.out.print("> "); 53 | } 54 | } catch(RSrvException rse) { 55 | System.out.println("Rserve exception: "+rse.getMessage()); 56 | } catch(Exception e) { 57 | System.out.println("Something went wrong, but it's not the Rserve: "+e.getMessage()); 58 | e.printStackTrace(); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Rserve/src/client/java-old/examples/t.java: -------------------------------------------------------------------------------- 1 | import org.rosuda.JRclient.*; 2 | import java.io.*; 3 | import java.util.*; 4 | 5 | // this is just a collection of various silly things you can do when 6 | // accessing Rserve. it's not very useful in particular, but it may 7 | // contain some demo code 8 | 9 | class TestException extends Exception { 10 | public TestException(String msg) { super(msg); } 11 | } 12 | 13 | public class t { 14 | public static void main(String args[]) { 15 | try { 16 | Rconnection c=new Rconnection((args.length>0)?args[0]:"127.0.0.1"); 17 | 18 | System.out.println("ok, connected, press to continue\n"); 19 | System.in.read(); 20 | 21 | { 22 | System.out.println("Test assigning of lists and vectors ..."); 23 | RList l = new RList(); 24 | l.put("a",new REXP(new int[] { 0,1,2,3})); 25 | l.put("b",new REXP(new double[] { 0.5,1.2,2.3,3.0})); 26 | System.out.println("assign x=pairlist, y=vector, z=data.frame"); 27 | c.assign("x", new REXP(REXP.XT_LIST_TAG, l)); 28 | c.assign("y", new REXP(REXP.XT_VECTOR, l)); 29 | c.assign("z", REXP.createDataFrame(l)); 30 | System.out.println("pull all three back to Java"); 31 | REXP x = c.eval("x"); 32 | System.out.println("x = "+x); 33 | x = c.eval("y"); 34 | System.out.println("y = "+x); 35 | x = c.eval("z"); 36 | System.out.println("z = "+x); 37 | } 38 | 39 | { // error handling 40 | System.out.println("Try to evaluave an invalid expression in try..."); 41 | String expr="foo.bar"; 42 | REXP x = c.eval("try({"+expr+"},silent=TRUE)"); 43 | if (x!=null) { 44 | REXP cl = x.getAttribute("class"); 45 | if (cl != null && cl.asString().equals("try-error")) { 46 | //throw new RErrorException(x.asString()); 47 | System.out.println("R reported an error: "+x.asString()); 48 | } else { 49 | System.out.println("Expression result: "+x); 50 | } 51 | } 52 | } 53 | 54 | { // factors 55 | System.out.println("test support of factors"); 56 | REXP f = c.eval("factor(paste('F',as.integer(runif(20)*5),sep=''))"); 57 | System.out.println("isFactor: "+f.isFactor()+"\nasFactor: "+f.asFactor()); 58 | if (!f.isFactor() || f.asFactor() == null) throw new TestException("factor test failed"); 59 | System.out.println("singe-level factor used to degenerate:"); 60 | f = c.eval("factor('foo')"); 61 | System.out.println("isFactor: "+f.isFactor()+"\nasFactor: "+f.asFactor()); 62 | if (!f.isFactor() || f.asFactor() == null) throw new TestException("single factor test failed"); 63 | } 64 | 65 | // lowess example 66 | System.out.println("lowess: create points"); 67 | double[] dataX = c.eval("rnorm(100)").asDoubleArray(); 68 | double[] dataY = c.eval("rnorm(100)").asDoubleArray(); 69 | System.out.println("lowess: assign points"); 70 | c.assign("x", dataX); 71 | c.assign("y", dataY); 72 | System.out.println("lowess: call lowess"); 73 | REXP xl = c.eval("lowess(x,y)"); 74 | // System.out.println("result = "+xl); 75 | RList l = xl.asList(); 76 | // System.out.println("list = "+l); 77 | System.out.println("lowess: retrieve points"); 78 | double[] lx = l.at("x").asDoubleArray(); 79 | double[] ly = l.at("y").asDoubleArray(); 80 | 81 | // matrix test 82 | System.out.println("matrix: create a matrix"); 83 | int m=100, n=100; 84 | double[] mat=new double[m*n]; 85 | int i=0; 86 | while (i0)?arg[0]:"127.0.0.1"); // make new connecton 11 | System.out.println("Server vesion: "+c.getServerVersion()); 12 | if (c.needLogin()) { // if server requires authentication, send one 13 | System.out.println("authentication required."); 14 | c.login("guest","guest"); 15 | } 16 | 17 | System.out.println("creating large data ..."); 18 | double[] m= new double[2*1024*1024]; 19 | int i=0; 20 | while (i<2*1024*1024) { m[i]=i; i++; }; 21 | 22 | System.out.println("assigning data ..."); 23 | // transport the data into R 24 | c.assign("m",m); 25 | System.out.println("create matrix ..."); 26 | // create a matrix from the data 27 | c.voidEval("m<-matrix(m,2048,1024)"); 28 | System.out.println("retireve matrix ..."); 29 | // just to see what you got: 30 | REXP r=c.eval("m"); 31 | System.out.println("get as matrix ..."); 32 | System.out.println("got: "+r); 33 | double[][] mx=r.asMatrix(); 34 | System.out.println("got m("+mx.length+","+mx[0].length+")"); 35 | 36 | c.close(); 37 | } catch(RSrvException rse) { 38 | System.out.println("Rserve exception: "+rse.getMessage()); 39 | } catch(Exception e) { 40 | System.out.println("Something went wrong, but it's not the Rserve: "+e.getMessage()); e.printStackTrace(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Rserve/src/client/java-old/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * old (deprecated) client interface to Rserve 3 | * 4 | *

The new REngine-based interface defined in the org.rosuda.REngine.Rserve is recommended 5 | */ 6 | package org.rosuda.JRclient ; 7 | 8 | -------------------------------------------------------------------------------- /Rserve/src/config.h: -------------------------------------------------------------------------------- 1 | /* src/config.h. Generated from config.h.in by configure. */ 2 | /* src/config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define if building universal (internal helper macro) */ 5 | /* #undef AC_APPLE_UNIVERSAL_BUILD */ 6 | 7 | /* Defined if the platform is big-endian */ 8 | /* #undef BS_BIG_ENDIAN */ 9 | 10 | /* Defined if the platform is little-endian */ 11 | #define BS_LITTLE_ENDIAN 1 12 | 13 | /* If defined Rserve supports unix crypt password encryption. */ 14 | #define HAS_CRYPT 1 15 | 16 | /* */ 17 | #define HAVE_CONNECT 1 18 | 19 | /* Define to 1 if you have the header file. */ 20 | #define HAVE_CRYPT_H 1 21 | 22 | /* Define to 1 if you have the `fork' function. */ 23 | #define HAVE_FORK 1 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_INTTYPES_H 1 27 | 28 | /* Define to 1 if you have the `dl' library (-ldl). */ 29 | #define HAVE_LIBDL 1 30 | 31 | /* Define to 1 if you have the `inet' library (-linet). */ 32 | /* #undef HAVE_LIBINET */ 33 | 34 | /* Define to 1 if you have the `nsl' library (-lnsl). */ 35 | /* #undef HAVE_LIBNSL */ 36 | 37 | /* Define to 1 if you have the `nsl_s' library (-lnsl_s). */ 38 | /* #undef HAVE_LIBNSL_S */ 39 | 40 | /* Define to 1 if you have the `socket' library (-lsocket). */ 41 | /* #undef HAVE_LIBSOCKET */ 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_MEMORY_H 1 45 | 46 | /* Define to 1 if you have the `memset' function. */ 47 | #define HAVE_MEMSET 1 48 | 49 | /* Define to 1 if you have the `mkdir' function. */ 50 | #define HAVE_MKDIR 1 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #define HAVE_NETINET_IN_H 1 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #define HAVE_NETINET_TCP_H 1 57 | 58 | /* Define to 1 if you have the `rmdir' function. */ 59 | #define HAVE_RMDIR 1 60 | 61 | /* Define to 1 if you have the `select' function. */ 62 | #define HAVE_SELECT 1 63 | 64 | /* Define to 1 if you have the `socket' function. */ 65 | #define HAVE_SOCKET 1 66 | 67 | /* Define to 1 if you have the header file. */ 68 | #define HAVE_STDINT_H 1 69 | 70 | /* Define to 1 if you have the header file. */ 71 | #define HAVE_STDLIB_H 1 72 | 73 | /* Define to 1 if you have the header file. */ 74 | #define HAVE_STRINGS_H 1 75 | 76 | /* Define to 1 if you have the header file. */ 77 | #define HAVE_STRING_H 1 78 | 79 | /* Define to 1 if you have the header file. */ 80 | #define HAVE_SYS_SOCKET_H 1 81 | 82 | /* Define to 1 if you have the header file. */ 83 | #define HAVE_SYS_STAT_H 1 84 | 85 | /* Define to 1 if you have the header file. */ 86 | #define HAVE_SYS_TIME_H 1 87 | 88 | /* Define to 1 if you have the header file. */ 89 | #define HAVE_SYS_TYPES_H 1 90 | 91 | /* Define to 1 if you have the header file. */ 92 | #define HAVE_SYS_UN_H 1 93 | 94 | /* Define to 1 if you have that is POSIX.1 compatible. */ 95 | #define HAVE_SYS_WAIT_H 1 96 | 97 | /* Define to 1 if you have the header file. */ 98 | #define HAVE_UNISTD_H 1 99 | 100 | /* Define to 1 if you have the `vfork' function. */ 101 | #define HAVE_VFORK 1 102 | 103 | /* Define to 1 if you have the header file. */ 104 | /* #undef HAVE_VFORK_H */ 105 | 106 | /* Define to 1 if `fork' works. */ 107 | #define HAVE_WORKING_FORK 1 108 | 109 | /* Define to 1 if `vfork' works. */ 110 | #define HAVE_WORKING_VFORK 1 111 | 112 | /* Define to the address where bug reports for this package should be sent. */ 113 | #define PACKAGE_BUGREPORT "Simon.Urbanek@r-project.org" 114 | 115 | /* Define to the full name of this package. */ 116 | #define PACKAGE_NAME "Rserve" 117 | 118 | /* Define to the full name and version of this package. */ 119 | #define PACKAGE_STRING "Rserve 0.4" 120 | 121 | /* Define to the one symbol short name of this package. */ 122 | #define PACKAGE_TARNAME "rserve" 123 | 124 | /* Define to the home page for this package. */ 125 | #define PACKAGE_URL "" 126 | 127 | /* Define to the version of this package. */ 128 | #define PACKAGE_VERSION "0.4" 129 | 130 | /* Define as the return type of signal handlers (`int' or `void'). */ 131 | #define RETSIGTYPE void 132 | 133 | /* Define to 1 if you have the ANSI C header files. */ 134 | #define STDC_HEADERS 1 135 | 136 | /* Define to 1 if you can safely include both and . */ 137 | #define TIME_WITH_SYS_TIME 1 138 | 139 | /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most 140 | significant byte first (like Motorola and SPARC, unlike Intel). */ 141 | #if defined AC_APPLE_UNIVERSAL_BUILD 142 | # if defined __BIG_ENDIAN__ 143 | # define WORDS_BIGENDIAN 1 144 | # endif 145 | #else 146 | # ifndef WORDS_BIGENDIAN 147 | /* # undef WORDS_BIGENDIAN */ 148 | # endif 149 | #endif 150 | 151 | /* Define to empty if `const' does not conform to ANSI C. */ 152 | /* #undef const */ 153 | 154 | /* Define to `int' if does not define. */ 155 | /* #undef pid_t */ 156 | 157 | /* Define to `int' if neither nor define. */ 158 | /* #undef socklen_t */ 159 | 160 | /* Define as `fork' if `vfork' does not work. */ 161 | /* #undef vfork */ 162 | -------------------------------------------------------------------------------- /Rserve/src/config.h.in: -------------------------------------------------------------------------------- 1 | /* src/config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define if building universal (internal helper macro) */ 4 | #undef AC_APPLE_UNIVERSAL_BUILD 5 | 6 | /* Defined if the platform is big-endian */ 7 | #undef BS_BIG_ENDIAN 8 | 9 | /* Defined if the platform is little-endian */ 10 | #undef BS_LITTLE_ENDIAN 11 | 12 | /* If defined Rserve supports unix crypt password encryption. */ 13 | #undef HAS_CRYPT 14 | 15 | /* */ 16 | #undef HAVE_CONNECT 17 | 18 | /* Define to 1 if you have the header file. */ 19 | #undef HAVE_CRYPT_H 20 | 21 | /* Define to 1 if you have the `fork' function. */ 22 | #undef HAVE_FORK 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_INTTYPES_H 26 | 27 | /* Define to 1 if you have the `dl' library (-ldl). */ 28 | #undef HAVE_LIBDL 29 | 30 | /* Define to 1 if you have the `inet' library (-linet). */ 31 | #undef HAVE_LIBINET 32 | 33 | /* Define to 1 if you have the `nsl' library (-lnsl). */ 34 | #undef HAVE_LIBNSL 35 | 36 | /* Define to 1 if you have the `nsl_s' library (-lnsl_s). */ 37 | #undef HAVE_LIBNSL_S 38 | 39 | /* Define to 1 if you have the `socket' library (-lsocket). */ 40 | #undef HAVE_LIBSOCKET 41 | 42 | /* Define to 1 if you have the header file. */ 43 | #undef HAVE_MEMORY_H 44 | 45 | /* Define to 1 if you have the `memset' function. */ 46 | #undef HAVE_MEMSET 47 | 48 | /* Define to 1 if you have the `mkdir' function. */ 49 | #undef HAVE_MKDIR 50 | 51 | /* Define to 1 if you have the header file. */ 52 | #undef HAVE_NETINET_IN_H 53 | 54 | /* Define to 1 if you have the header file. */ 55 | #undef HAVE_NETINET_TCP_H 56 | 57 | /* Define to 1 if you have the `rmdir' function. */ 58 | #undef HAVE_RMDIR 59 | 60 | /* Define to 1 if you have the `select' function. */ 61 | #undef HAVE_SELECT 62 | 63 | /* Define to 1 if you have the `socket' function. */ 64 | #undef HAVE_SOCKET 65 | 66 | /* Define to 1 if you have the header file. */ 67 | #undef HAVE_STDINT_H 68 | 69 | /* Define to 1 if you have the header file. */ 70 | #undef HAVE_STDLIB_H 71 | 72 | /* Define to 1 if you have the header file. */ 73 | #undef HAVE_STRINGS_H 74 | 75 | /* Define to 1 if you have the header file. */ 76 | #undef HAVE_STRING_H 77 | 78 | /* Define to 1 if you have the header file. */ 79 | #undef HAVE_SYS_SOCKET_H 80 | 81 | /* Define to 1 if you have the header file. */ 82 | #undef HAVE_SYS_STAT_H 83 | 84 | /* Define to 1 if you have the header file. */ 85 | #undef HAVE_SYS_TIME_H 86 | 87 | /* Define to 1 if you have the header file. */ 88 | #undef HAVE_SYS_TYPES_H 89 | 90 | /* Define to 1 if you have the header file. */ 91 | #undef HAVE_SYS_UN_H 92 | 93 | /* Define to 1 if you have that is POSIX.1 compatible. */ 94 | #undef HAVE_SYS_WAIT_H 95 | 96 | /* Define to 1 if you have the header file. */ 97 | #undef HAVE_UNISTD_H 98 | 99 | /* Define to 1 if you have the `vfork' function. */ 100 | #undef HAVE_VFORK 101 | 102 | /* Define to 1 if you have the header file. */ 103 | #undef HAVE_VFORK_H 104 | 105 | /* Define to 1 if `fork' works. */ 106 | #undef HAVE_WORKING_FORK 107 | 108 | /* Define to 1 if `vfork' works. */ 109 | #undef HAVE_WORKING_VFORK 110 | 111 | /* Define to the address where bug reports for this package should be sent. */ 112 | #undef PACKAGE_BUGREPORT 113 | 114 | /* Define to the full name of this package. */ 115 | #undef PACKAGE_NAME 116 | 117 | /* Define to the full name and version of this package. */ 118 | #undef PACKAGE_STRING 119 | 120 | /* Define to the one symbol short name of this package. */ 121 | #undef PACKAGE_TARNAME 122 | 123 | /* Define to the home page for this package. */ 124 | #undef PACKAGE_URL 125 | 126 | /* Define to the version of this package. */ 127 | #undef PACKAGE_VERSION 128 | 129 | /* Define as the return type of signal handlers (`int' or `void'). */ 130 | #undef RETSIGTYPE 131 | 132 | /* Define to 1 if you have the ANSI C header files. */ 133 | #undef STDC_HEADERS 134 | 135 | /* Define to 1 if you can safely include both and . */ 136 | #undef TIME_WITH_SYS_TIME 137 | 138 | /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most 139 | significant byte first (like Motorola and SPARC, unlike Intel). */ 140 | #if defined AC_APPLE_UNIVERSAL_BUILD 141 | # if defined __BIG_ENDIAN__ 142 | # define WORDS_BIGENDIAN 1 143 | # endif 144 | #else 145 | # ifndef WORDS_BIGENDIAN 146 | # undef WORDS_BIGENDIAN 147 | # endif 148 | #endif 149 | 150 | /* Define to empty if `const' does not conform to ANSI C. */ 151 | #undef const 152 | 153 | /* Define to `int' if does not define. */ 154 | #undef pid_t 155 | 156 | /* Define to `int' if neither nor define. */ 157 | #undef socklen_t 158 | 159 | /* Define as `fork' if `vfork' does not work. */ 160 | #undef vfork 161 | -------------------------------------------------------------------------------- /Rserve/src/include/Parse.h: -------------------------------------------------------------------------------- 1 | /* This is a fall-back for R versions that don't have R_ext/Parse.h 2 | (R versions before 2.1.0) */ 3 | 4 | #ifndef R_EXT_PARSE_H_ 5 | #define R_EXT_PARSE_H_ 6 | 7 | typedef enum { 8 | PARSE_NULL, 9 | PARSE_OK, 10 | PARSE_INCOMPLETE, 11 | PARSE_ERROR, 12 | PARSE_EOF 13 | } ParseStatus; 14 | 15 | SEXP R_ParseVector(SEXP, int, ParseStatus *); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /Rserve/src/include/Win32/Startup.h: -------------------------------------------------------------------------------- 1 | /* 2 | * R : A Computer Language for Statistical Data Analysis 3 | * Copyright (C) 1999-2003 The R Development Core Team 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef STARTUP_H_ 21 | #define STARTUP_H_ 22 | 23 | #include /* TRUE/FALSE */ 24 | 25 | #ifdef Win32 26 | typedef int (*blah1) (char *, char *, int, int); 27 | typedef void (*blah2) (char *, int); 28 | typedef void (*blah3) (); 29 | typedef void (*blah4) (char *); 30 | typedef int (*blah5) (char *); 31 | typedef void (*blah6) (int); 32 | typedef enum {RGui, RTerm, LinkDLL} UImode; 33 | #endif 34 | 35 | /* Startup Actions */ 36 | typedef enum { 37 | SA_NORESTORE,/* = 0 */ 38 | SA_RESTORE, 39 | SA_DEFAULT,/* was === SA_RESTORE */ 40 | SA_NOSAVE, 41 | SA_SAVE, 42 | SA_SAVEASK, 43 | SA_SUICIDE 44 | } SA_TYPE; 45 | 46 | typedef struct 47 | { 48 | Rboolean R_Quiet; 49 | Rboolean R_Slave; 50 | Rboolean R_Interactive; 51 | Rboolean R_Verbose; 52 | Rboolean LoadSiteFile; 53 | Rboolean LoadInitFile; 54 | Rboolean DebugInitFile; 55 | SA_TYPE RestoreAction; 56 | SA_TYPE SaveAction; 57 | unsigned long vsize; 58 | unsigned long nsize; 59 | unsigned long max_vsize; 60 | unsigned long max_nsize; 61 | unsigned long ppsize; 62 | int NoRenviron; 63 | 64 | /* Permanent copy of the command line arguments and the number 65 | of them passed to the application. 66 | These are populated via the routine R_set_command_line_arguments() 67 | called from R_common_command_line(). 68 | */ 69 | int NumCommandLineArgs; 70 | char **CommandLineArgs; 71 | 72 | #ifdef Win32 73 | char *rhome; /* R_HOME */ 74 | char *home; /* HOME */ 75 | blah1 ReadConsole; 76 | blah2 WriteConsole; 77 | blah3 CallBack; 78 | blah4 message; 79 | blah5 yesnocancel; 80 | blah6 busy; 81 | UImode CharacterMode; 82 | Rboolean DebugMenuitem; 83 | #endif 84 | } structRstart; 85 | 86 | typedef structRstart *Rstart; 87 | 88 | void R_DefParams(Rstart); 89 | void R_SetParams(Rstart); 90 | void R_SetWin32(Rstart); 91 | void R_SizeFromEnv(Rstart); 92 | void R_common_command_line(int *, char **, Rstart); 93 | 94 | void R_set_command_line_arguments(int argc, char **argv, Rstart Rp); 95 | 96 | void setup_Rmainloop(void); 97 | 98 | /* originally from Defn.h : */ 99 | 100 | void R_CleanUp(SA_TYPE, int, int); 101 | void R_StartUp(void); 102 | 103 | FILE *R_OpenInitFile(void); 104 | FILE *R_OpenSysInitFile(void); 105 | FILE *R_OpenSiteFile(void); 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /Rserve/src/include/Win32/config.h: -------------------------------------------------------------------------------- 1 | /* config.h for Windows 2 | This file is based on a config.h as generated by configure run 3 | on a MinGW gcc system. Most of it is not used, because many 4 | parts of Rserve have its own Win32 code, but it may become handy 5 | at some later point. 6 | 7 | Last update: Rserve 0.4-5, R 2.4.0, MinGW gcc 3.4.5 8 | */ 9 | 10 | /* Defined if the platform is little-endian */ 11 | #define BS_LITTLE_ENDIAN 1 12 | 13 | /* Define to 1 if you have the header file. */ 14 | #define HAVE_INTTYPES_H 1 15 | 16 | /* Define to 1 if your system has a GNU libc compatible `malloc' function, and 17 | to 0 otherwise. */ 18 | #define HAVE_MALLOC 1 19 | 20 | /* Define to 1 if you have the header file. */ 21 | #define HAVE_MEMORY_H 1 22 | 23 | /* Define to 1 if you have the `memset' function. */ 24 | #define HAVE_MEMSET 1 25 | 26 | /* Define to 1 if you have the `mkdir' function. */ 27 | #define HAVE_MKDIR 1 28 | 29 | /* Define to 1 if you have the `rmdir' function. */ 30 | #define HAVE_RMDIR 1 31 | 32 | /* Define to 1 if you have the header file. */ 33 | #define HAVE_STDINT_H 1 34 | 35 | /* Define to 1 if you have the header file. */ 36 | #define HAVE_STDLIB_H 1 37 | 38 | /* Define to 1 if you have the header file. */ 39 | #define HAVE_STRINGS_H 1 40 | 41 | /* Define to 1 if you have the header file. */ 42 | #define HAVE_STRING_H 1 43 | 44 | /* Define to 1 if you have the header file. */ 45 | #define HAVE_SYS_STAT_H 1 46 | 47 | /* Define to 1 if you have the header file. */ 48 | #define HAVE_SYS_TIME_H 1 49 | 50 | /* Define to 1 if you have the header file. */ 51 | #define HAVE_SYS_TYPES_H 1 52 | 53 | /* Define to 1 if you have the header file. */ 54 | #define HAVE_UNISTD_H 1 55 | 56 | /* Define to 1 if you have the ANSI C header files. */ 57 | #define STDC_HEADERS 1 58 | 59 | /* Define to 1 if you can safely include both and . */ 60 | #define TIME_WITH_SYS_TIME 1 61 | 62 | 63 | -------------------------------------------------------------------------------- /Rserve/src/include/Win32/psignal.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * * 3 | * signal.h * 4 | * * 5 | * Freely redistributable and modifiable. Use at your own risk. * 6 | * * 7 | * Copyright 1994-1999 The Downhill Project * 8 | * http://www.ede.com/free/u2nt * 9 | * * 10 | *****************************************************************************/ 11 | 12 | 13 | /* 14 | Original version taken at 15 | Changes (g.m.): 16 | 10.06.1999: Made self contained - Changed some names 17 | 11.06.1999: Added 'sigsetjmp' and 'siglongjmp' 18 | 12.06.1999: Added pause and sigsuspend (require a version (also 19 | a non POSIX one) of sleep; if your system don't have it 20 | define DONT_HAVE_SLEEP) 21 | 27/06/1999: (BDR) convert sigsetjmp and siglongjmp macros to (,,) 22 | 12/07/1999: (BDR) fix sigsetjmp macro to set saved_mask 23 | 24 | */ 25 | 26 | #ifndef _PSIGNAL_H_ 27 | #define _PSIGNAL_H_ 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #define SIGHUP 1 /* hangup */ 34 | #define SIGINT 2 /* interrupt */ 35 | #define SIGQUIT 3 /* quit */ 36 | #define SIGILL 4 /* illegal instruction (not reset when caught) */ 37 | #define SIGTRAP 5 /* trace trap (not reset when caught) */ 38 | #define SIGEMT 7 /* EMT instruction */ 39 | #define SIGFPE 8 /* floating point exception */ 40 | #define SIGKILL 9 /* kill (cannot be caught or ignored) */ 41 | #define SIGBUS 10 /* bus error */ 42 | #define SIGSEGV 11 /* segmentation violation */ 43 | #define SIGSYS 12 /* bad argument to system call */ 44 | #define SIGPIPE 13 /* write on a pipe with no one to read it */ 45 | #define SIGALRM 14 /* alarm clock */ 46 | #define SIGTERM 15 /* software termination signal from kill */ 47 | #define SIGURG 16 /* urgent condition on IO channel */ 48 | #define SIGSTOP 17 /* sendable stop signal not from tty */ 49 | #define SIGTSTP 18 /* stop signal from tty */ 50 | #define SIGCONT 19 /* continue a stopped process */ 51 | #define SIGCHLD 20 /* to parent on child stop or exit */ 52 | #define SIGCLD 20 /* System V name for SIGCHLD */ 53 | #define SIGBREAK 21 /* to readers pgrp upon background tty read */ 54 | #define SIGABRT 22 /* used by abort */ 55 | #define SIGIO 23 /* input/output possible signal */ 56 | #define SIGPOLL SIGIO /* System V name for SIGIO */ 57 | #define SIGXCPU 24 /* exceeded CPU time limit */ 58 | #define SIGXFSZ 25 /* exceeded file size limit */ 59 | #define SIGVTALRM 26 /* virtual time alarm */ 60 | #define SIGPROF 27 /* profiling time alarm */ 61 | #define SIGWINCH 28 /* window changed */ 62 | #define SIGLOST 29 /* resource lost (eg, record-lock lost) */ 63 | #define SIGUSR1 30 /* user defined signal 1 */ 64 | #define SIGUSR2 31 /* user defined signal 2 */ 65 | #define NSIG 32 /* signal 0 implied */ 66 | 67 | #ifndef RC_INVOKED 68 | 69 | /* 70 | * A pointer to a signal handler function. A signal handler takes a 71 | * single int, which is the signal it handles. 72 | */ 73 | typedef void (*sighandler_t)(int nSig); 74 | #ifndef _SIGSET_T_ 75 | #define _SIGSET_T_ 76 | typedef int sigset_t; 77 | #endif /* Not _SIGSET_T_ */ 78 | 79 | 80 | /* 81 | * These are special values of signal handler pointers which are 82 | * used to send a signal to the default handler (SIG_DFL), ignore 83 | * the signal (SIG_IGN), or indicate an error return (SIG_ERR). 84 | */ 85 | #define SIG_DFL ((sighandler_t) 0) 86 | #define SIG_IGN ((sighandler_t) 1) 87 | #define SIG_ERR ((sighandler_t) -1) 88 | 89 | #ifdef __cplusplus 90 | extern "C" { 91 | #endif 92 | 93 | 94 | 95 | 96 | 97 | /* Signal mask actions ===================================================== */ 98 | #define SIG_BLOCK 0 99 | #define SIG_UNBLOCK 1 100 | #define SIG_SETMASK 2 101 | 102 | /* Signal flag actions ===================================================== */ 103 | #define SA_NOCLDSTOP 1 104 | #define SA_RESETHAND 2 105 | 106 | 107 | /* Struct stuff **************************************************************/struct sigaction 108 | { 109 | void (*sa_handler)(int); 110 | sigset_t sa_mask; 111 | int sa_flags; 112 | }; 113 | 114 | typedef struct 115 | { 116 | jmp_buf jmpbuf; /* Calling environment. */ 117 | int mask_was_saved; /* Saved the signal mask? */ 118 | sigset_t saved_mask; /* Saved signal mask. */ 119 | } sigjmp_buf[1]; 120 | 121 | 122 | 123 | /* Prototype stuff ***********************************************************/ 124 | unsigned long sigsetmask(unsigned long signal_Block_MaskNew); 125 | unsigned long sigblock(unsigned long signal_Block_MaskNew); 126 | int sighold(int signal_Number); 127 | int sigrelse(int signal_Number); 128 | int sigaction(int signal_Number,struct sigaction* sigaction_Info, 129 | struct sigaction* signaction_InfoOld); 130 | int sigaddset(sigset_t* sigset_Info,int signal_Number); 131 | int sigdelset(sigset_t* sigset_Info,int signal_Number); 132 | int sigemptyset(sigset_t* sigset_Info); 133 | int sigfillset(sigset_t* sigset_Info); 134 | int sigismember(sigset_t* sigset_Info,int signal_Number); 135 | int sigpending(sigset_t* sigset_Info); 136 | int sigprocmask(int mask_Function,sigset_t* sigset_Info, 137 | sigset_t* sigset_InfoOld); 138 | sighandler_t signal(int signal_Number, sighandler_t); 139 | void raise(int); 140 | int pause(void); 141 | int sigsuspend(sigset_t* sigset_Info); 142 | 143 | /* Re-mapped functions ===================================================== */ 144 | 145 | #define sigmask(signal_Index) (1<<(signal_Index-1)) 146 | 147 | /* 148 | This must be a macro, since we want setjmp working in the 149 | calling environment 150 | */ 151 | /* 152 | #define sigsetjmp(jb, sm) (\ 153 | sm?sigprocmask(SIG_SETMASK,NULL,&jb->saved_mask):0,\ 154 | jb->mask_was_saved=sm,\ 155 | setjmp(jb->jmpbuf)) 156 | 157 | we only currently use the case sm=0, so avoid compiler warnings by */ 158 | 159 | #define sigsetjmp(jb, sm) (jb->mask_was_saved=0, setjmp(jb->jmpbuf)) 160 | 161 | 162 | /* We can transform this in a function but ... */ 163 | 164 | #define siglongjmp(jb, val) (((jb->mask_was_saved)?\ 165 | sigprocmask(SIG_SETMASK, &jb->saved_mask, 0):0),\ 166 | longjmp(jb->jmpbuf, val)) 167 | 168 | 169 | 170 | #ifdef __cplusplus 171 | } 172 | #endif 173 | 174 | #endif /* Not RC_INVOKED */ 175 | 176 | #endif /* Not _PSIGNAL_H_ */ 177 | -------------------------------------------------------------------------------- /Rserve/src/include/sbthread.h: -------------------------------------------------------------------------------- 1 | /*****************************************************************\ 2 | * sbthread - system-independent basic threads * 3 | * (C)Copyright 2001 Simon Urbanek * 4 | *---------------------------------------------------------------* 5 | * Supported platforms: unix w pthread, Win32 * 6 | \*****************************************************************/ 7 | 8 | #ifndef __SBTHREAD_H__ 9 | #define __SBTHREAD_H__ 10 | 11 | 12 | #include 13 | 14 | #define decl_sbthread void * 15 | #define sbthread_result(A) (void *)(A) 16 | #define sbthread_mutex pthread_mutex_t 17 | 18 | sbthread_mutex *sbthread_create_mutex() { 19 | pthread_mutex_t lm=PTHREAD_MUTEX_INITIALIZER; 20 | pthread_mutex_t *m=(pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); 21 | memcpy(m,&lm,sizeof(pthread_mutex_t)); 22 | return m; 23 | }; 24 | 25 | #define sbthread_lock_mutex(M) pthread_mutex_lock(M); 26 | #define sbthread_unlock_mutex(M) pthread_mutex_unlock(M); 27 | void sbthread_destroy_mutex(sbthread_mutex *m) { 28 | pthread_mutex_destroy(m); free(m); 29 | }; 30 | 31 | int sbthread_create(void * (thr)(void *), void *par) { 32 | pthread_t Thread; 33 | pthread_attr_t ThreadAttr; 34 | 35 | pthread_attr_init(&ThreadAttr); 36 | pthread_attr_setdetachstate(&ThreadAttr,PTHREAD_CREATE_DETACHED); 37 | return pthread_create(&Thread,&ThreadAttr,*thr,par); 38 | }; 39 | 40 | 41 | 42 | #endif /* __SBTHREAD_H__ */ 43 | -------------------------------------------------------------------------------- /Rserve/src/m.sh: -------------------------------------------------------------------------------- 1 | cc -c -o Rserv.o Rserv.c -DDAEMON -I/usr/share/R/include -Iinclude 2 | cc -c -o session.o session.c -DDAEMON 3 | cc -c -o md5.o md5.c -DDAEMON 4 | cc -o Rserve Rserv.o session.o md5.o -L/usr/lib64/R/lib -lR -ldl -lcrypt 5 | 6 | cc -c -o Rserv_d.o Rserv.c -DNODAEMON -DRSERV_DEBUG -g -DRSERV_DEBUG -g -I/usr/share/R/include -Iinclude 7 | cc -o Rserve.dbg Rserv_d.o session.o md5.o -L/usr/lib64/R/lib -lR -ldl -lcrypt 8 | 9 | -------------------------------------------------------------------------------- /Rserve/src/md5.h: -------------------------------------------------------------------------------- 1 | #ifndef MD5_H 2 | #define MD5_H 3 | 4 | #ifdef __alpha 5 | typedef unsigned int uint32; 6 | #else 7 | typedef unsigned long uint32; 8 | #endif 9 | 10 | struct MD5Context { 11 | uint32 buf[4]; 12 | uint32 bits[2]; 13 | unsigned char in[64]; 14 | }; 15 | 16 | extern void MD5Init(); 17 | extern void MD5Update(); 18 | extern void MD5Final(); 19 | extern void MD5Transform(); 20 | 21 | /* 22 | * This is needed to make RSAREF happy on some MS-DOS compilers. 23 | */ 24 | typedef struct MD5Context MD5_CTX; 25 | 26 | #endif /* !MD5_H */ 27 | -------------------------------------------------------------------------------- /Rserve/src/mergefat: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Usage: mergefat 4 | # 5 | # Merges into possibly fat file and places the result in . 6 | # is assumed to be single-arch only. 7 | # Checks whether /usr/bin/lipo exists and uses cp if it doesn't. 8 | # 9 | # (C)2006,8 Simon Urbanek 10 | 11 | LIPO=/usr/bin/lipo 12 | 13 | if test -e "${LIPO}" -a -e "$2"; then 14 | myarch=`${LIPO} -detailed_info "$1"| sed -n -e 's|.\{0,\}architecture:\{0,1\} ||p'` 15 | binarch=`${LIPO} -detailed_info "$2"| sed -n -e 's|.\{0,\}architecture:\{0,1\} ||p'` 16 | if test "$myarch" = "$binarch"; then 17 | # the target is a single-arch of the same type as us - just replace 18 | cp "$1" "$2" 19 | else 20 | # try to remove our arch - if it fails (it is not fat or doesn't have our arch), 21 | # take the whole thing 22 | ${LIPO} "$2" -remove "$myarch" -o liposuction || cp "$2" liposuction 23 | ${LIPO} -create liposuction "$1" -o "$2" 24 | rm -f liposuction 25 | fi 26 | else 27 | cp "$1" "$2" 28 | fi 29 | -------------------------------------------------------------------------------- /Rserve/src/session.c: -------------------------------------------------------------------------------- 1 | /* 2 | * implements a vector of session scructures accessible by a session key. 3 | * 4 | * Author : Simon Urbanek 5 | * Created: 2005/08/30 6 | * License: GPL2 7 | * 8 | * $Id: session.c 157 2006-04-21 18:52:34Z urbaneks $ 9 | */ 10 | 11 | #include "config.h" 12 | #include "session.h" 13 | #ifdef HAVE_MEMORY_H 14 | #include 15 | #else 16 | #include 17 | #endif 18 | #include 19 | 20 | static struct sSession *session=0; 21 | static int sessions=0; 22 | static int sessions_allocated=0; 23 | 24 | /* find a session */ 25 | struct sSession *find_session(char key[16]) { 26 | int i=0; 27 | while (i128 && sessions < sessions_allocated/2) { 60 | sessions_allocated = sessions_allocated/2 + 64; 61 | session = (struct sSession*) realloc(session, sessions_allocated * sizeof(struct sSession)); 62 | } 63 | return; 64 | } 65 | i++; 66 | } 67 | } 68 | 69 | int total_sessions() { return sessions; } 70 | struct sSession *first_session() { return session; } 71 | struct sSession *next_session(struct sSession* current) { 72 | if (current=session+sessions-1) return 0; 73 | return current+1; 74 | } 75 | 76 | /*--- The following makes the indenting behavior of emacs compatible 77 | with Xcode's 4/4 setting ---*/ 78 | /* Local Variables: */ 79 | /* indent-tabs-mode: t */ 80 | /* tab-width: 4 */ 81 | /* c-basic-offset: 4 */ 82 | /* End: */ 83 | -------------------------------------------------------------------------------- /Rserve/src/session.h: -------------------------------------------------------------------------------- 1 | #ifndef SESSION_H__ 2 | #define SESSION_H__ 3 | 4 | struct sSession { 5 | unsigned char key[16]; 6 | int s; 7 | }; 8 | 9 | struct sSession *new_session(char key[16]); 10 | struct sSession *find_session(char key[16]); 11 | void free_session(char key[16]); 12 | 13 | /* functions for walking thorugh sessions. 14 | warning: next_session becomes invalid if new_session or 15 | free_session is called between first_session and 16 | and any subsequent next_session 17 | */ 18 | struct sSession *first_session(); 19 | struct sSession *next_session(struct sSession* current); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /Rserve/version: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | VER=`sed -n 's/.*Rserve v\([0-9.\-]*\).*/\1/p' src/Rsrv.h|head -n 1` 4 | if test "x$1" = "x-f"; then 5 | echo "Rserve_${VER}.tar.gz" 6 | else 7 | echo "${VER}" 8 | fi 9 | -------------------------------------------------------------------------------- /RserveVisualStudio/RPackage/RPackage.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {E98C4BED-755C-43C7-A587-04E1BF6EFBE8} 23 | RPackage 24 | 25 | 26 | 27 | Application 28 | true 29 | v120 30 | MultiByte 31 | 32 | 33 | Utility 34 | true 35 | v120 36 | MultiByte 37 | 38 | 39 | Application 40 | false 41 | v120 42 | true 43 | MultiByte 44 | 45 | 46 | Utility 47 | false 48 | v120 49 | true 50 | MultiByte 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | Level3 72 | Disabled 73 | true 74 | 75 | 76 | true 77 | 78 | 79 | 80 | 81 | Level3 82 | Disabled 83 | true 84 | 85 | 86 | true 87 | 88 | 89 | mkdir $(SolutionDir)\..\Rserve\inst 90 | copy $(SolutionDir)$(Platform)\$(Configuration)\*.exe $(SolutionDir)\..\Rserve\inst 91 | cd $(SolutionDir)\.. 92 | mkdir RServetempLibrary 93 | R CMD INSTALL --no-multiarch --no-libs --no-test-load --build --library=RServetempLibrary Rserve 94 | rmdir /s /q RServetempLibrary 95 | 96 | $(SolutiontDir)\..\*.zip 97 | 98 | 99 | 100 | 101 | Level3 102 | MaxSpeed 103 | true 104 | true 105 | true 106 | 107 | 108 | true 109 | true 110 | true 111 | 112 | 113 | 114 | 115 | Level3 116 | MaxSpeed 117 | true 118 | true 119 | true 120 | 121 | 122 | true 123 | true 124 | true 125 | 126 | 127 | 128 | 129 | 130 | 131 | mkdir $(SolutionDir)\..\Rserve\inst 132 | copy $(SolutionDir)$(Platform)\$(Configuration)\*.exe $(SolutionDir)\..\Rserve\inst 133 | cd $(SolutionDir)\.. 134 | mkdir RServetempLibrary 135 | R CMD INSTALL --no-multiarch --no-libs --no-test-load --build --library=RServetempLibrary Rserve 136 | rmdir /s /q RServetempLibrary 137 | $(SolutiontDir)\..\*.zip 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /RserveVisualStudio/Rserve.sdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/deployr-rserve/348120aa75ebabd391a6d3040c34b487656a8f06/RserveVisualStudio/Rserve.sdf -------------------------------------------------------------------------------- /RserveVisualStudio/Rserve.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.40629.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Rserve", "Rserve\Rserve.vcxproj", "{9A9A0D8A-FBF3-49FC-9A84-F394ACA4E72D}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A9B64833-041A-472C-A548-5ECFE74E4233}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RPackage", "RPackage\RPackage.vcxproj", "{E98C4BED-755C-43C7-A587-04E1BF6EFBE8}" 11 | ProjectSection(ProjectDependencies) = postProject 12 | {9A9A0D8A-FBF3-49FC-9A84-F394ACA4E72D} = {9A9A0D8A-FBF3-49FC-9A84-F394ACA4E72D} 13 | EndProjectSection 14 | EndProject 15 | Global 16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 17 | Debug|Mixed Platforms = Debug|Mixed Platforms 18 | Debug|Win32 = Debug|Win32 19 | Debug|x64 = Debug|x64 20 | Release|Mixed Platforms = Release|Mixed Platforms 21 | Release|Win32 = Release|Win32 22 | Release|x64 = Release|x64 23 | EndGlobalSection 24 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 25 | {9A9A0D8A-FBF3-49FC-9A84-F394ACA4E72D}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 26 | {9A9A0D8A-FBF3-49FC-9A84-F394ACA4E72D}.Debug|Mixed Platforms.Build.0 = Debug|Win32 27 | {9A9A0D8A-FBF3-49FC-9A84-F394ACA4E72D}.Debug|Win32.ActiveCfg = Debug|Win32 28 | {9A9A0D8A-FBF3-49FC-9A84-F394ACA4E72D}.Debug|Win32.Build.0 = Debug|Win32 29 | {9A9A0D8A-FBF3-49FC-9A84-F394ACA4E72D}.Debug|x64.ActiveCfg = Debug|x64 30 | {9A9A0D8A-FBF3-49FC-9A84-F394ACA4E72D}.Debug|x64.Build.0 = Debug|x64 31 | {9A9A0D8A-FBF3-49FC-9A84-F394ACA4E72D}.Release|Mixed Platforms.ActiveCfg = Release|Win32 32 | {9A9A0D8A-FBF3-49FC-9A84-F394ACA4E72D}.Release|Mixed Platforms.Build.0 = Release|Win32 33 | {9A9A0D8A-FBF3-49FC-9A84-F394ACA4E72D}.Release|Win32.ActiveCfg = Release|Win32 34 | {9A9A0D8A-FBF3-49FC-9A84-F394ACA4E72D}.Release|Win32.Build.0 = Release|Win32 35 | {9A9A0D8A-FBF3-49FC-9A84-F394ACA4E72D}.Release|x64.ActiveCfg = Release|x64 36 | {9A9A0D8A-FBF3-49FC-9A84-F394ACA4E72D}.Release|x64.Build.0 = Release|x64 37 | {E98C4BED-755C-43C7-A587-04E1BF6EFBE8}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 38 | {E98C4BED-755C-43C7-A587-04E1BF6EFBE8}.Debug|Mixed Platforms.Build.0 = Debug|Win32 39 | {E98C4BED-755C-43C7-A587-04E1BF6EFBE8}.Debug|Win32.ActiveCfg = Debug|Win32 40 | {E98C4BED-755C-43C7-A587-04E1BF6EFBE8}.Debug|Win32.Build.0 = Debug|Win32 41 | {E98C4BED-755C-43C7-A587-04E1BF6EFBE8}.Debug|x64.ActiveCfg = Debug|x64 42 | {E98C4BED-755C-43C7-A587-04E1BF6EFBE8}.Debug|x64.Build.0 = Debug|x64 43 | {E98C4BED-755C-43C7-A587-04E1BF6EFBE8}.Release|Mixed Platforms.ActiveCfg = Release|Win32 44 | {E98C4BED-755C-43C7-A587-04E1BF6EFBE8}.Release|Mixed Platforms.Build.0 = Release|Win32 45 | {E98C4BED-755C-43C7-A587-04E1BF6EFBE8}.Release|Win32.ActiveCfg = Release|Win32 46 | {E98C4BED-755C-43C7-A587-04E1BF6EFBE8}.Release|Win32.Build.0 = Release|Win32 47 | {E98C4BED-755C-43C7-A587-04E1BF6EFBE8}.Release|x64.ActiveCfg = Release|x64 48 | {E98C4BED-755C-43C7-A587-04E1BF6EFBE8}.Release|x64.Build.0 = Release|x64 49 | EndGlobalSection 50 | GlobalSection(SolutionProperties) = preSolution 51 | HideSolutionNode = FALSE 52 | EndGlobalSection 53 | EndGlobal 54 | -------------------------------------------------------------------------------- /RserveVisualStudio/Rserve/R.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/deployr-rserve/348120aa75ebabd391a6d3040c34b487656a8f06/RserveVisualStudio/Rserve/R.lib -------------------------------------------------------------------------------- /RserveVisualStudio/Rserve/generate_R_lib.bat: -------------------------------------------------------------------------------- 1 | 2 | REM taken from: http://stackoverflow.com/questions/33136486/program-in-c-compiled-with-embedded-r-dll-crashes-when-calling-standard-c-functi 3 | 4 | setlocal 5 | call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" amd64 6 | SET MACHINE=x64 7 | SET LIBNAME=R 8 | dumpbin /exports %LIBNAME%.dll > %LIBNAME%.exports 9 | echo LIBRARY R > %LIBNAME%.def 10 | echo EXPORTS >> %LIBNAME%.def 11 | for /f "skip=19 tokens=4" %%A in (%LIBNAME%.exports) do echo %%A >> %LIBNAME%.def 12 | 13 | REM manually edit R.def to remove 'printf' definition 14 | 15 | start /wait notepad.exe %LIBNAME%.def 16 | lib /def:%LIBNAME%.def /out:%LIBNAME%.lib /machine:%MACHINE% 17 | endlocal -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd). 40 | 41 | 42 | --------------------------------------------------------------------------------