[Rcpp-commits] r4180 - in pkg/RcppClassicExamples: . R man src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Dec 29 16:50:24 CET 2012
Author: edd
Date: 2012-12-29 16:50:23 +0100 (Sat, 29 Dec 2012)
New Revision: 4180
Added:
pkg/RcppClassicExamples/ChangeLog
pkg/RcppClassicExamples/DESCRIPTION
pkg/RcppClassicExamples/NAMESPACE
pkg/RcppClassicExamples/R/RcppDateExample.R
pkg/RcppClassicExamples/R/RcppExample.R
pkg/RcppClassicExamples/R/RcppMatrixExample.R
pkg/RcppClassicExamples/R/RcppParamsExample.R
pkg/RcppClassicExamples/R/RcppStringVectorExample.R
pkg/RcppClassicExamples/R/RcppVectorExample.R
pkg/RcppClassicExamples/cleanup
pkg/RcppClassicExamples/man/RcppClassicExamples-packages.Rd
pkg/RcppClassicExamples/man/RcppDataFrame.Rd
pkg/RcppClassicExamples/man/RcppDate.Rd
pkg/RcppClassicExamples/man/RcppExample.Rd
pkg/RcppClassicExamples/man/RcppParams.Rd
pkg/RcppClassicExamples/man/RcppResultSet.Rd
pkg/RcppClassicExamples/man/RcppVector.Rd
pkg/RcppClassicExamples/src/Makevars
pkg/RcppClassicExamples/src/Makevars.win
pkg/RcppClassicExamples/src/classicRcppDateExample.cpp
pkg/RcppClassicExamples/src/classicRcppExample.cpp
pkg/RcppClassicExamples/src/classicRcppMatrixExample.cpp
pkg/RcppClassicExamples/src/classicRcppParamsExample.cpp
pkg/RcppClassicExamples/src/classicRcppStringVectorExample.cpp
pkg/RcppClassicExamples/src/classicRcppVectorExample.cpp
Log:
New package RcppClassicExamples recovering the old API examples now purged from RcppExamples
Added: pkg/RcppClassicExamples/ChangeLog
===================================================================
--- pkg/RcppClassicExamples/ChangeLog (rev 0)
+++ pkg/RcppClassicExamples/ChangeLog 2012-12-29 15:50:23 UTC (rev 4180)
@@ -0,0 +1,8 @@
+2010-12-27 Dirk Eddelbuettel <edd at debian.org>
+
+ * DESCRIPTION: Version 0.1.0 --- new package, split off RcppExamples
+ 0.1.4 which now covers the Rcpp API only
+
+ * man/*: Updated to stress that this API is deprecated, added links
+ to Rcpp documentation
+
Copied: pkg/RcppClassicExamples/DESCRIPTION (from rev 4174, pkg/RcppExamples/DESCRIPTION)
===================================================================
--- pkg/RcppClassicExamples/DESCRIPTION (rev 0)
+++ pkg/RcppClassicExamples/DESCRIPTION 2012-12-29 15:50:23 UTC (rev 4180)
@@ -0,0 +1,17 @@
+Package: RcppClassicExamples
+Title: Examples using RcppClassic to interface R and C++
+Version: 0.1.0
+Date: $Date$
+Author: Dirk Eddelbuettel and Romain Francois, based on code written
+ during 2005 and 2006 by Dominick Samperi
+Maintainer: Dirk Eddelbuettel <edd at debian.org>
+Description: Examples for Seamless R and C++ integration
+ The Rcpp package contains a C++ library that facilitates the integration of
+ R and C++ in various ways. The deprecated RcppClassic package provides
+ backwards-compatibility for the previous version of the API, and this
+ package provides some usage examples for the deprecated older API..
+Depends: R (>= 2.11.0), Rcpp, RcppClassic
+LinkingTo: Rcpp, RcppClassic
+Suggests: RUnit
+URL: http://dirk.eddelbuettel.com/code/rcpp.html, http://romainfrancois.blog.free.fr/index.php?category/R-package/Rcpp
+License: GPL (>= 2)
Copied: pkg/RcppClassicExamples/NAMESPACE (from rev 4174, pkg/RcppExamples/NAMESPACE)
===================================================================
--- pkg/RcppClassicExamples/NAMESPACE (rev 0)
+++ pkg/RcppClassicExamples/NAMESPACE 2012-12-29 15:50:23 UTC (rev 4180)
@@ -0,0 +1,12 @@
+useDynLib(RcppClassicExamples)
+
+export(RcppExample,
+ print.RcppExample,
+ RcppDateExample,
+ RcppParamsExample,
+ RcppVectorExample,
+ RcppMatrixExample,
+ RcppStringVectorExample
+)
+
+
Added: pkg/RcppClassicExamples/R/RcppDateExample.R
===================================================================
--- pkg/RcppClassicExamples/R/RcppDateExample.R (rev 0)
+++ pkg/RcppClassicExamples/R/RcppDateExample.R 2012-12-29 15:50:23 UTC (rev 4180)
@@ -0,0 +1,41 @@
+
+## RcppDateExample.R: Rcpp R/C++ interface class library RcppDate example
+##
+## Copyright (C) 2008 Dirk Eddelbuettel
+## Copyright (C) 2009 - 2012 Dirk Eddelbuettel and Romain Francois
+##
+## This file is part of Rcpp.
+##
+## Rcpp is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 2 of the License, or
+## (at your option) any later version.
+##
+## Rcpp is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
+
+RcppDateExample <- function(dv, dtv) {
+
+ ## Check that params is properly set.
+ if (missing(dv)) {
+ cat("\nIn R, setting default argument for dv\n")
+ dv <- Sys.Date() + -2:2
+ }
+
+ if (missing(dtv)) {
+ cat("\nIn R, setting default argument for dtv\n")
+ dtv <- Sys.time() + (-2:2)*0.5
+ }
+
+ ## Make the call...
+ val <- .Call("classicRcppDateExample", dv, dtv,
+ PACKAGE="RcppClassicExamples")
+
+ val
+}
+
Copied: pkg/RcppClassicExamples/R/RcppExample.R (from rev 4174, pkg/RcppExamples/R/RcppExample.R)
===================================================================
--- pkg/RcppClassicExamples/R/RcppExample.R (rev 0)
+++ pkg/RcppClassicExamples/R/RcppExample.R 2012-12-29 15:50:23 UTC (rev 4180)
@@ -0,0 +1,124 @@
+## RcppExample.R: Rcpp R/C++ interface class library example
+##
+## Copyright (C) 2008 Dirk Eddelbuettel
+## Copyright (C) 2009 - 2012 Dirk Eddelbuettel and Romain Francois
+##
+## This file is part of Rcpp.
+##
+## Rcpp is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 2 of the License, or
+## (at your option) any later version.
+##
+## Rcpp is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
+
+RcppExample <- function(params, nlist, numvec, nummat, df, datevec, stringvec,
+ fnvec, fnlist) {
+
+ ## Most of the input parameter checking here is not really
+ ## necessary because it is done in the Rcpp code.
+
+ ## Check that params is properly formatted.
+ if (missing(params)) {
+ cat("Setting default argument for params\n")
+ params <- list(method='BFGS',
+ tolerance=1.0e-8,
+ maxIter=1000,
+ startDate=as.Date('2006-7-15'))
+ }
+
+ ## Check nlist
+ if (missing(nlist)) {
+ cat("Setting default argument for nlist\n")
+ nlist <- list(ibm = 80.50, hp = 53.64, c = 45.41)
+ } else if (!is.numeric(unlist(nlist))) {
+ stop("The values in nlist must be numeric")
+ }
+
+ ## Check numvec
+ if (missing(numvec)) {
+ cat("Setting default argument for numvec\n")
+ numvec <- seq(1,5) # numerical vector
+ } else if (!is.vector(numvec)) { ## Check numvec argument
+ stop("numvec must be a vector");
+ }
+
+ ## Check nummat
+ if (missing(nummat)) {
+ cat("Setting default argument for nummat\n")
+ nummat <- matrix(seq(1,20),4,5) # numerical matrix
+ } else if (!is.matrix(nummat)) {
+ stop("nummat must be a matrix");
+ }
+
+ ## Check df
+ if (missing(df)) {
+ cat("Setting default argument for data frame\n")
+ df <- data.frame(a=c(TRUE, TRUE, FALSE), b=I(c('a','b','c')))
+ }
+
+ ## Check datevec
+ if (missing(datevec)) {
+ cat("Setting default argument for date vector\n")
+ datestr <- c('2006-6-10', '2006-7-12', '2006-8-10')
+ datevec <- as.Date(datestr, "%Y-%m-%d") # date vector
+ }
+
+ ## Check stringvec
+ if (missing(stringvec)) {
+ cat("Setting default argument for string vector\n")
+ stringvec <- c("hello", "world", "fractal") # string vector
+ }
+
+ ## Check fnvec
+ if (missing(fnvec)) {
+ cat("Setting default argument for function vector\n")
+ fnvec <- function(x) { sum(x) } # Add up components of vector
+ }
+
+ ## Check fnlist
+ if (missing(fnlist)) {
+ cat("Setting default argument for function list\n")
+ fnlist <- function(l) { # Return vector with 1 added to each component
+ vec <- c(l$alpha + 1, l$beta + 1, l$gamma + 1)
+ vec
+ }
+ }
+
+ ## Finally ready to make the call...
+ val <- .Call("Rcpp_Example", params, nlist, numvec, nummat,
+ df, datevec, stringvec, fnvec, fnlist,
+ PACKAGE="RcppClassicExamples"
+ )
+
+ ## Define a class for the return value so we can control what gets
+ ## printed when a variable assigned this value is typed on a line by itself.
+ ## This has the effect of calling the function print.RcppExample(). The
+ ## function (defined below) simply prints the names of the fields that are
+ ## available. Access each field with val$name.
+ class(val) <- "RcppExample"
+
+ val
+}
+
+print.RcppExample <- function(x,...) {
+ cat('\nIn R, names defined in RcppExample return list:\n')
+ cat('(Use result$name or result[[i]] to access)\n')
+ namevec <- names(x)
+ for(i in 1:length(namevec)) {
+ cat(format(i, width=2), ': ', format(namevec[i], width=12))
+ if (is.atomic(x[[i]])) {
+ cat(format(x[[i]]))
+ } else {
+ cat(format("..."))
+ }
+ cat('\n')
+ }
+}
+
Added: pkg/RcppClassicExamples/R/RcppMatrixExample.R
===================================================================
--- pkg/RcppClassicExamples/R/RcppMatrixExample.R (rev 0)
+++ pkg/RcppClassicExamples/R/RcppMatrixExample.R 2012-12-29 15:50:23 UTC (rev 4180)
@@ -0,0 +1,29 @@
+
+## RcppMatrixExample.R: Rcpp R/C++ interface class library RcppMatrix example
+##
+## Copyright (C) 2008 Dirk Eddelbuettel
+## Copyright (C) 2009 - 2012 Dirk Eddelbuettel and Romain Francois
+##
+## This file is part of Rcpp.
+##
+## Rcpp is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 2 of the License, or
+## (at your option) any later version.
+##
+## Rcpp is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
+
+RcppMatrixExample <- function(mat=matrix(seq(1,9)^2, ncol=3)) {
+
+ ## Make the call...
+ val <- .Call("classicRcppMatrixExample", mat,
+ PACKAGE="RcppClassicExamples")
+
+ val
+}
Added: pkg/RcppClassicExamples/R/RcppParamsExample.R
===================================================================
--- pkg/RcppClassicExamples/R/RcppParamsExample.R (rev 0)
+++ pkg/RcppClassicExamples/R/RcppParamsExample.R 2012-12-29 15:50:23 UTC (rev 4180)
@@ -0,0 +1,39 @@
+
+## RcppParamsExample.R: Rcpp R/C++ interface class library RcppParams example
+##
+## Copyright (C) 2008 Dirk Eddelbuettel
+## Copyright (C) 2009 - 2012 Dirk Eddelbuettel and Romain Francois
+##
+## This file is part of Rcpp.
+##
+## Rcpp is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 2 of the License, or
+## (at your option) any later version.
+##
+## Rcpp is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
+
+RcppParamsExample <- function(params) {
+
+ ## Check that params is properly set.
+ if (missing(params)) {
+ cat("\nIn R, setting default argument for params\n")
+ params <- list(method='BFGS',
+ tolerance=1.0e-8,
+ maxIter=1000,
+ startDate=as.Date('2006-7-15'))
+ }
+
+ ## Make the call...
+ val <- .Call("classicRcppParamsExample", params,
+ PACKAGE="RcppClassicExamples")
+
+ val
+}
+
Added: pkg/RcppClassicExamples/R/RcppStringVectorExample.R
===================================================================
--- pkg/RcppClassicExamples/R/RcppStringVectorExample.R (rev 0)
+++ pkg/RcppClassicExamples/R/RcppStringVectorExample.R 2012-12-29 15:50:23 UTC (rev 4180)
@@ -0,0 +1,29 @@
+
+## RcppStringVectorExample.R: Rcpp R/C++ interface class library
+##
+## Copyright (C) 2008 Dirk Eddelbuettel
+## Copyright (C) 2009 - 2012 Dirk Eddelbuettel and Romain Francois
+##
+## This file is part of Rcpp.
+##
+## Rcpp is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 2 of the License, or
+## (at your option) any later version.
+##
+## Rcpp is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
+
+RcppStringVectorExample <- function(vec=c("Tick", "Tack", "Tock")) {
+
+ ## Make the call...
+ val <- .Call("classicRcppStringVectorExample", vec,
+ PACKAGE="RcppClassicExamples")
+
+ val
+}
Added: pkg/RcppClassicExamples/R/RcppVectorExample.R
===================================================================
--- pkg/RcppClassicExamples/R/RcppVectorExample.R (rev 0)
+++ pkg/RcppClassicExamples/R/RcppVectorExample.R 2012-12-29 15:50:23 UTC (rev 4180)
@@ -0,0 +1,29 @@
+
+## RcppVectorExample.R: Rcpp R/C++ interface class library RcppVector example
+##
+## Copyright (C) 2008 Dirk Eddelbuettel
+## Copyright (C) 2009 - 2012 Dirk Eddelbuettel and Romain Francois
+##
+## This file is part of Rcpp.
+##
+## Rcpp is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 2 of the License, or
+## (at your option) any later version.
+##
+## Rcpp is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
+
+RcppVectorExample <- function(vec=seq(1,9)^2) {
+
+ ## Make the call...
+ val <- .Call("classicRcppVectorExample", vec,
+ PACKAGE= "RcppClassicExamples")
+
+ val
+}
Copied: pkg/RcppClassicExamples/cleanup (from rev 4174, pkg/RcppExamples/cleanup)
===================================================================
--- pkg/RcppClassicExamples/cleanup (rev 0)
+++ pkg/RcppClassicExamples/cleanup 2012-12-29 15:50:23 UTC (rev 4180)
@@ -0,0 +1,2 @@
+
+rm -f src/*.o src/*.so */*~ *~
Added: pkg/RcppClassicExamples/man/RcppClassicExamples-packages.Rd
===================================================================
--- pkg/RcppClassicExamples/man/RcppClassicExamples-packages.Rd (rev 0)
+++ pkg/RcppClassicExamples/man/RcppClassicExamples-packages.Rd 2012-12-29 15:50:23 UTC (rev 4180)
@@ -0,0 +1,42 @@
+\name{RcppClassicExamples-package}
+\alias{RcppClassicExamples-package}
+\alias{RcppClassicExamples}
+\docType{package}
+\title{Examples for the deprecated Rcpp R/C++ Interface library API}
+\description{
+ This package shows some simple examples for the use of the deprecated
+ \emph{classic} API from the first implementation of \pkg{Rcpp}.
+
+ Note that the \pkg{RcppClassic} package has been deprecated since
+ 2010, all new development should use the \pkg{Rcpp} package instead.
+}
+\details{
+ The \pkg{Rcpp} package provides a number of C++ classes that ease
+ access to C++ from R. This comprises both passing parameters to
+ functions, as well as returning results back from C++ to R.
+
+ Two APIs are supported. The first is an older API which was first
+ introduced mostly in 2006 and extended in 2008. This interface is used
+ by a few other packages and will be supported going forward in the
+ \link[RcppClassic]{RcppClassic-package} package.
+
+ A second and newer API that was started in 2009 offers more
+ functionality, see the \link[Rcpp]{Rcpp-package} package.
+
+ The \pkg{RcppExamples} package provides some simple examples for use
+ of \pkg{Rcpp}.
+}
+\seealso{
+ See the \link[RcppExamples]{RcppExamples-package} for examples of the
+ recommended \pkg{Rcpp} API and \link[Rcpp]{Rcpp-package} for
+ documentation on the recommended API to extend R with C++ code, while
+ the deprecated \link[RcppClassic]{RcppClassic-package} documents the
+ older, deprecated API.
+}
+\author{Dominick Samperi wrote the initial versions of Rcpp (and
+ RcppTemplate) during 2005 and 2006. Dirk Eddelbuettel made some
+ additions, and became maintainer in 2008. Dirk Eddelbuettel and Romain
+ Francois have been extending Rcpp since 2009.
+}
+\keyword{package}
+
Added: pkg/RcppClassicExamples/man/RcppDataFrame.Rd
===================================================================
--- pkg/RcppClassicExamples/man/RcppDataFrame.Rd (rev 0)
+++ pkg/RcppClassicExamples/man/RcppDataFrame.Rd 2012-12-29 15:50:23 UTC (rev 4180)
@@ -0,0 +1,60 @@
+\name{RcppDataFrame}
+\alias{RcppDataFrame}
+\title{Rcpp::DataFrame example for Rcpp -- deprecated API}
+\description{
+ A \code{DataFrame} can be passed C++ and can be instantiated as a
+ corresponding C++ object using the Rcpp API.
+
+ This example shows (in the corresponding C++ code) how to access,
+ modify and create a data frame.
+
+ Note that the \pkg{RcppClassic} package has been deprecated since
+ 2010, all new development should use the \pkg{Rcpp} package instead.
+}
+\details{
+ Usage of \code{Rcpp::DataFrame} is fully defined in
+ the respective header file.
+
+ The C++ source file corresponding to the this function does the
+ following (inside of a \code{try/catch} block):
+
+ \preformatted{%
+ // construct the data.frame object
+ Rcpp::DataFrame DF = Rcpp::DataFrame(Dsexp);
+
+ // and access each column by name
+ Rcpp::IntegerVector a = DF["a"];
+ Rcpp::CharacterVector b = DF["b"];
+ Rcpp::DateVector c = DF["c"];
+
+ // do something
+ a[2] = 42;
+ b[1] = "foo";
+ c[0] = c[0] + 7; // move up a week
+
+ // create a new data frame
+ Rcpp::DataFrame NDF =
+ Rcpp::DataFrame::create(Rcpp::Named("a")=a,
+ Rcpp::Named("b")=b,
+ Rcpp::Named("c")=c);
+
+ // and return old and new in list
+ return(Rcpp::List::create(Rcpp::Named("origDataFrame")=DF,
+ Rcpp::Named("newDataFrame")=NDF));
+ }
+}
+\author{Dirk Eddelbuettel and Romain Francois}
+\seealso{
+ See the \link[RcppExamples]{RcppExamples-package} for examples of the
+ recommended \pkg{Rcpp} API and \link[Rcpp]{Rcpp-package} for
+ documentation on the recommended API to extend R with C++ code, while
+ the deprecated \link[RcppClassic]{RcppClassic-package} documents the
+ older, deprecated API.
+}
+\examples{
+ \dontrun{
+ RcppDataFrame()
+ }
+}
+\keyword{programming}
+\keyword{interface}
Added: pkg/RcppClassicExamples/man/RcppDate.Rd
===================================================================
--- pkg/RcppClassicExamples/man/RcppDate.Rd (rev 0)
+++ pkg/RcppClassicExamples/man/RcppDate.Rd 2012-12-29 15:50:23 UTC (rev 4180)
@@ -0,0 +1,105 @@
+\name{RcppDate}
+\alias{RcppDate}
+\alias{RcppDatetime}
+\alias{RcppDateVector}
+\alias{RcppDatetimeVector}
+\alias{RcppDateExample}
+\title{C++ classes for interfacing date and datetime R objects -- deprecated API}
+\description{
+ \code{RcppDate}, \code{RcppDatetime}, \code{RcppDateVector} and
+ \code{RcppDatetimeVector} are C++ classes defined in their respective
+ headers files. They are part of the 'classic' Rcpp API. These classes
+ pass scalars and vectors of \R objects of types \code{Date} and
+ \code{POSIXct}, respectively, to C++ via the \code{.Call()} function
+ interface.
+
+ Member functions are provided to query the dimension of the vector or
+ matrix object, convert it in a corresponding \code{C} representation.
+
+ \R objects of type \code{Date}, and hence the \code{RcppDate} and
+ \code{RcppDateVector} objects, are internally represented as an
+ integer counting days since the epoch, i.e. January 1,
+ 1970. Similarly, \R objects of type \code{POSIXct} and the
+ \code{RcppDatetime} and \code{RcppDatetimeVector} objects, are
+ internally represented as seconds since the epoch. However, \R
+ extends the POSIX standard by using a double leading to microsecond
+ precision in timestamps. This is fully supported by \code{Rcpp} as
+ well.
+
+ The new API currently has the classes \code{Rcpp::Date}, \code{Rcpp::Datetime},
+ \code{Rcpp::DateVector} and \code{Rcpp::DatetimeVector} which are preferred
+ for new developments, as is the rest of the new API in the \pkg{Rcpp} package
+ while the \pkg{RcppClassic} package has been deprecated since
+ 2010.
+}
+\details{
+ Usage of the \code{RcppDate}, \code{RcppDatetime} (and their vector
+ extensions) in \code{C++} is fully defined in the respective header
+ files \code{RcppDate.h} and \code{RcppDatetime.h}.
+
+ As example, consider a call from \R to \code{C++} such as
+
+ \preformatted{
+ # an R example passing one type of each class to a function
+ # someFunction in package somePackage
+ val <- .Call("someFunction",
+ Sys.Date(), # current date
+ Sys.time(), # current timestamp
+ as.Date("2000-02-25")
+ + 0:5, # date vector
+ ISOdatetime(1999,12,31,23,59,0)
+ + (0:5)*0.250, # datetime vector
+ PACKAGE="somePackage")
+ }
+
+ At the \code{C++} level, the corresponding code to assign these parameter to
+ \code{C++} objects is can be as follows::
+ \preformatted{%
+ SEXP someFunction(SEXP ds, SEXP dts,
+ SEXP dvs, SEXP dtvs) {
+
+ RcppDate d(ds);
+ RcppDatetime dt(dts);
+ RcppDateVector dv(dvs);
+ RcppDatetimeVector dtv(dtvs);
+ }
+ }
+
+ Standard accessor functions are defined, see \code{RcppDate.h} and
+ \code{RcppDatetime.h} for details.
+
+ Objects of these types can also be returned via \code{RcppResultSet}.
+
+}
+\references{
+ \emph{Writing R Extensions}, available at \url{http:www.r-project.org}.
+}
+\seealso{
+ \code{RcppResultSet}.
+
+ See the \link[RcppExamples]{RcppExamples-package} for examples of the
+ recommended \pkg{Rcpp} API and \link[Rcpp]{Rcpp-package} for
+ documentation on the recommended API to extend R with C++ code, while
+ the deprecated \link[RcppClassic]{RcppClassic-package} documents the
+ older, deprecated API.
+}
+\author{Dominick Samperi wrote the initial versions of Rcpp (and
+ RcppTemplate) during 2005 and 2006. Dirk Eddelbuettel made some
+ additions, and became maintainer in 2008. Dirk Eddelbuettel and Romain
+ Francois have been extending Rcpp since 2009.
+}
+\examples{
+
+# set up date and datetime vectors
+dvec <- Sys.Date() + -2:2
+dtvec <- Sys.time() + (-2:2)*0.5
+
+# call the underlying C++ function
+result <- RcppDateExample(dvec, dtvec)
+
+# inspect returned object
+result
+}
+\keyword{programming}
+\keyword{interface}
+
Copied: pkg/RcppClassicExamples/man/RcppExample.Rd (from rev 4174, pkg/RcppExamples/man/RcppExample.Rd)
===================================================================
--- pkg/RcppClassicExamples/man/RcppExample.Rd (rev 0)
+++ pkg/RcppClassicExamples/man/RcppExample.Rd 2012-12-29 15:50:23 UTC (rev 4180)
@@ -0,0 +1,112 @@
+\name{RcppExample}
+\alias{RcppExample}
+\alias{print.RcppExample}
+\title{Rcpp R / C++ interface example -- deprecated API}
+\description{
+ \code{RcppExample} illustrates how the older \code{Rcpp} R/C++
+ interface class library is used. It provides fairly complete coverage
+ for the older \sQuote{classic} API.
+
+ Note that the \pkg{RcppClassic} package has been deprecated since
+ 2010, all new development should use the \pkg{Rcpp} package instead.
+}
+\usage{
+RcppExample(params, nlist, numvec, nummat, df, datevec, stringvec, fnvec, fnlist)
+\method{print}{RcppExample}(x,...)
+}
+\arguments{
+ \item{params}{A heterogeneous list specifying \code{method} (string),
+ \code{tolerance} (double), \code{maxIter} (int).}
+ \item{nlist}{a list of named numeric values (double or int).}
+ \item{numvec}{a numeric 1D vector (double or int).}
+ \item{nummat}{a numeric 2D matrix (double or int).}
+ \item{df}{a data frame.}
+ \item{datevec}{a vector of Date's.}
+ \item{stringvec}{a vector of strings.}
+ \item{fnvec}{an R function with numeric vector argument.}
+ \item{fnlist}{an R function with list argument.}
+ \item{x}{Object of type \code{RcppExample}.}
+ \item{...}{Extra named parameters.}
+ }
+\details{
+ The C++ represention of data frames are not passed back to R in a form
+ that R recognizes as a data frame, but it is a simple matter to do the
+ conversion. For example, the return value named \code{PreDF} (see
+ return values below) is not seen as a data frame on the R side (thus
+ the name "pre-data frame"), but it can be converted to a data frame
+ using \code{df <- data.frame(result$PreDF)}.
+
+ The print.RcppExample() function is defined so that we can control
+ what gets printed when a variable assigned the return value is entered
+ on a line by itself. It is defined to simply list the names of the
+ fields returned (see RcppExample.R).
+}
+\value{
+ \code{RcppExample} returns a list containing:
+ \item{method}{string input paramter}
+ \item{tolerance}{double input paramter}
+ \item{maxIter}{int input parameter}
+ \item{nlFirstName}{first name in nlist}
+ \item{nlFirstValue}{first value in nlist}
+ \item{matD}{R matrix from an RcppMatrix<double> object}
+ \item{stlvec}{R vector from a vector<double> object}
+ \item{stlmat}{R matrix from a vector<vector<double> > object}
+ \item{a}{R matrix from C/C++ matrix}
+ \item{v}{R vector from C/C++ vector}
+ \item{strings}{R vector of strings from vector<string> object}
+ \item{InputDF}{a data frame passed in from R}
+ \item{PreDF}{a data frame created on C++ side to be passed back to R}
+ \item{params}{input parameter list (this is redundant because we returned the input parameters above)}
+}
+\author{Dominick Samperi wrote the initial versions of Rcpp (and
+ RcppTemplate) during 2005 and 2006. Dirk Eddelbuettel made some
+ additions, and became maintainer in 2008. Dirk Eddelbuettel and Romain
+ Francois have been extending Rcpp since 2009.
+}
+\references{
+ \emph{Writing R Extensions}, available at \url{http:www.r-project.org}.
+}
+\seealso{
+ See the \link[RcppExamples]{RcppExamples-package} for examples of the
+ recommended \pkg{Rcpp} API and \link[Rcpp]{Rcpp-package} for
+ documentation on the recommended API to extend R with C++ code, while
+ the deprecated \link[RcppClassic]{RcppClassic-package} documents the
+ older, deprecated API.
+}
+\examples{
+
+params <- list(method='BFGS',
+ tolerance=1.0e-8,
+ maxIter=1000,
+ startDate=as.Date('2006-7-15'))
+
+nlist <- list(ibm = 80.50, hp = 53.64, c = 45.41)
+
+numvec <- seq(1,5) # numerical vector
+
+nummat <- matrix(seq(1,20),4,5) # numerical matrix
+
+stringvec <- c("hello", "world", "fractal") # string vector
+
+datestr <- c('2006-6-10', '2006-7-12', '2006-8-10')
+datevec <- as.Date(datestr, "\%Y-\%m-\%d") # date vector
+
+df <- data.frame(a=c(TRUE, TRUE, FALSE), b=I(c('a','b','c')),
+c=c('beta', 'beta', 'gamma'), dates=datevec)
+
+fnvec <- function(x) { sum(x) } # Add up components of vector
+
+fnlist <- function(l) { # Return vector with 1 added to each component
+ vec <- c(l$alpha + 1, l$beta + 1, l$gamma + 1)
+ vec
+}
+
+result <- RcppExample(params, nlist, numvec, nummat, df, datevec,
+ stringvec, fnvec, fnlist)
+
+result
+
+}
+
+\keyword{programming}
+\keyword{interface}
Added: pkg/RcppClassicExamples/man/RcppParams.Rd
===================================================================
--- pkg/RcppClassicExamples/man/RcppParams.Rd (rev 0)
+++ pkg/RcppClassicExamples/man/RcppParams.Rd 2012-12-29 15:50:23 UTC (rev 4180)
@@ -0,0 +1,105 @@
+\name{RcppParams}
+\alias{RcppParams}
+\alias{RcppParamsExample}
+\title{C++ class for receiving (scalar) parameters from R -- deprecated API}
+\description{
+ \code{RcppParams} is a C++ class defined in \code{Rcpp.h} that receive
+ any number of scalar parameters of types in a single named list object
+ from \R through the \code{.Call()} function.
+
+ The parameters can be of different types that are limited to the \R
+ types \code{numeric}, \code{integer}, \code{character}, \code{logical}
+ or \code{Date}. These types are mapped into, respectively, the
+ corresponding C++ types \code{double}, \code{int}, \code{string},
+ \code{bool} and \code{Date} (a custom class defined by \code{Rcpp}.
+
+ \code{RcppParams} is part of the old deprecated Rcpp API, and should
+ be replaces by \code{Rcpp::List} which is more flexible and can be
+ used for both inputs and outputs. \code{RcppParams} is retained for
+ backwards compatibility, but should be avoided in new projects and
+ replaced in old projects.
+
+ Note that the \pkg{RcppClassic} package has been deprecated since
+ 2010, all new development should use the \pkg{Rcpp} package instead.
+}
+\arguments{
+ \item{params}{A heterogeneous list specifying \code{method} (string),
+ \code{tolerance} (double), \code{maxIter} (int) and \code{startDate}
+ (Date in R, RcppDate in C++).}
+}
+\value{
+ \code{RcppExample} returns a list containing:
+ \item{method}{string input paramter}
+ \item{tolerance}{double input paramter}
+ \item{maxIter}{int input parameter}
+ \item{startDate}{Date type with starting date}
+ \item{params}{input parameter list (this is redundant because we
+ returned the input parameters above)}
+}
+\details{
+ Usage of \code{RcppParams} from \R via \code{.Call()} is as follows:
+ \preformatted{%
+ # an R example passing one type of each class to a function
+ # someFunction in package somePackage
+ val <- .Call("someFunction",
+ list(pie=3.1415, magicanswer=42, sometext="foo",
+ yesno=true, today=Sys.date()),
+ PACKAGE="somePackage")
+ }
+
+ At the C++ level, the corresponding code to assign these parameter to
+ C++ objects is
+ \preformatted{%
+ SEXP someFunction(SEXP params) {
+ RcppParams par(params);
+ double p = par.getDoubleValue("pie");
+ int magic = par.getIntValue("magicanswer");
+ string txt = par.getStringValue("sometext");
+ bool yn = par.getBoolValue("yesno");
+ RcppDate d = par.getDateValue("today");
+ // some calculations ...
+ // some return values ...
+ }
+ }
+ As the lookup is driven by the names givem at the \R level, order is
+ not important. It is however important that the types match. Errors
+ are typically caught and an exception is thrown.
+
+ The class member function \code{checkNames} can be used to verify that the
+ \code{SEXP} object passed to the function contains a given set of
+ named object.
+}
+\references{
+ \emph{Writing R Extensions}, available at \url{http:www.r-project.org}.
+}
+\seealso{
+ \code{RcppExample}.
+
+ See the \link[RcppExamples]{RcppExamples-package} for examples of the
+ recommended \pkg{Rcpp} API and \link[Rcpp]{Rcpp-package} for
+ documentation on the recommended API to extend R with C++ code, while
+ the deprecated \link[RcppClassic]{RcppClassic-package} documents the
+ older, deprecated API.
+}
+\author{Dominick Samperi wrote the initial versions of Rcpp (and
+ RcppTemplate) during 2005 and 2006. Dirk Eddelbuettel made some
+ additions, and became maintainer in 2008. Dirk Eddelbuettel and Romain
+ Francois have been extending Rcpp since 2009.
+}
+\examples{
+
+# set up some value
+params <- list(method='BFGS',
+ tolerance=1.0e-5,
+ maxIter=100,
+ startDate=as.Date('2006-7-15'))
+
+# call the underlying C++ function
+result <- RcppParamsExample(params)
+
+# inspect returned object
+result
+
+}
+\keyword{programming}
+\keyword{interface}
Added: pkg/RcppClassicExamples/man/RcppResultSet.Rd
===================================================================
--- pkg/RcppClassicExamples/man/RcppResultSet.Rd (rev 0)
+++ pkg/RcppClassicExamples/man/RcppResultSet.Rd 2012-12-29 15:50:23 UTC (rev 4180)
@@ -0,0 +1,104 @@
+\name{RcppResultSet}
+\alias{RcppResultSet}
+\title{C++ class for sending C++ objects back to R -- deprecated API}
+\description{
+ \code{RcppResultSet} is a C++ class defined in \code{RcppResultSet.h} that can
+ assign any number of C++ objects to \R in a single named list object
+ as the \code{SEXP} return value of a \code{.Call()} function call. It
+ is part of the classic API.
+
+ The C++ objects can be of different types that are limited to
+ types \code{double}, \code{int}, \code{string}, vectors of
+ \code{double} or \code{int} (with explicit dimensions),
+ matrices of \code{double} or \code{int} (with explicit dimensions),
+ STL vectors of \code{double}, \code{int} or \code{string}, STL
+ \sQuote{vector of vectors} of types \code{double} or \code{int} (all
+ with implicit dimensions), the internal types \code{RcppDate}, \code{RcppDateVector},
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/rcpp -r 4180
More information about the Rcpp-commits
mailing list