[Rcpp-commits] r3081 - in pkg/RcppEigen: . R inst inst/skeleton man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jun 15 21:04:16 CEST 2011
Author: dmbates
Date: 2011-06-15 21:04:15 +0200 (Wed, 15 Jun 2011)
New Revision: 3081
Added:
pkg/RcppEigen/R/RcppEigen.package.skeleton.R
pkg/RcppEigen/inst/skeleton/
pkg/RcppEigen/inst/skeleton/Makevars
pkg/RcppEigen/inst/skeleton/Makevars.win
pkg/RcppEigen/inst/skeleton/rcppeigen_hello_world.R
pkg/RcppEigen/inst/skeleton/rcppeigen_hello_world.cpp
pkg/RcppEigen/inst/skeleton/rcppeigen_hello_world.h
pkg/RcppEigen/man/RcppEigen.package.skeleton.Rd
Modified:
pkg/RcppEigen/NAMESPACE
Log:
Add RcppEigen.package.skeleton and support files.
Modified: pkg/RcppEigen/NAMESPACE
===================================================================
--- pkg/RcppEigen/NAMESPACE 2011-06-15 19:01:43 UTC (rev 3080)
+++ pkg/RcppEigen/NAMESPACE 2011-06-15 19:04:15 UTC (rev 3081)
@@ -1,9 +1,10 @@
useDynLib(RcppEigen)
-import(Rcpp)
+#import(Rcpp)
#exportPattern("^[[:alpha:]]+")
export(fastLm,
- fastLmPure
+ fastLmPure,
+ RcppEigen.package.skeleton
)
S3method(fastLm, default)
Added: pkg/RcppEigen/R/RcppEigen.package.skeleton.R
===================================================================
--- pkg/RcppEigen/R/RcppEigen.package.skeleton.R (rev 0)
+++ pkg/RcppEigen/R/RcppEigen.package.skeleton.R 2011-06-15 19:04:15 UTC (rev 3081)
@@ -0,0 +1,121 @@
+## RcppEigen.package.skeleton.R: makes a skeleton for a package that wants to use RcppEigen
+##
+## Copyright (C) 2011 Dirk Eddelbuettel, Romain Francois and Douglas Bates
+##
+## This file is part of RcppEigen.
+##
+## RcppEigen 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.
+##
+## RcppEigen 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 RcppEigen. If not, see <http://www.gnu.org/licenses/>.
+
+RcppEigen.package.skeleton <- function(
+ name = "anRpackage", list = character(), environment = .GlobalEnv,
+ path = ".", force = FALSE, namespace = TRUE,
+ code_files = character(),
+ example_code = TRUE ){
+
+ env <- parent.frame(1)
+
+ if( !length(list) ){
+ fake <- TRUE
+ assign( "Rcpp.fake.fun", function(){}, envir = env )
+ } else {
+ fake <- FALSE
+ }
+
+ # first let the traditional version do its business
+ call <- match.call()
+ call[[1]] <- as.name("package.skeleton")
+ call[["namespace"]] <- namespace
+ if( "example_code" %in% names( call ) ){
+ # remove the example_code argument
+ call[["example_code"]] <- NULL
+ }
+ if( fake ){
+ call[["list"]] <- "Rcpp.fake.fun"
+ }
+
+ tryCatch( eval( call, envir = env ), error = function(e){
+ stop( "error while calling `package.skeleton`" )
+ } )
+
+ message( "\nAdding RcppEigen settings" )
+
+ # now pick things up
+ root <- file.path( path, name )
+
+ # Add Rcpp to the DESCRIPTION
+ DESCRIPTION <- file.path( root, "DESCRIPTION" )
+ if( file.exists( DESCRIPTION ) ){
+ x <- cbind( read.dcf( DESCRIPTION ),
+ "Depends" = sprintf( "Rcpp (>= %s), RcppEigen (>= %s) ",
+ packageDescription("Rcpp")[["Version"]],
+ packageDescription("RcppEigen")[["Version"]]),
+ "LinkingTo" = "Rcpp, RcppEigen" )
+ write.dcf( x, file = DESCRIPTION )
+ message( " >> added Depends: Rcpp, RcppEigen" )
+ message( " >> added LinkingTo: Rcpp, RcppEigen" )
+ }
+
+ # if there is a NAMESPACE, add a useDynLib
+ NAMESPACE <- file.path( root, "NAMESPACE")
+ if( file.exists( NAMESPACE ) ){
+ lines <- readLines( NAMESPACE )
+ if( ! grepl( "useDynLib", lines ) ){
+ lines <- c( sprintf( "useDynLib(%s)", name), lines)
+ writeLines( lines, con = NAMESPACE )
+ message( " >> added useDynLib directive to NAMESPACE" )
+ }
+ }
+
+ # lay things out in the src directory
+ src <- file.path( root, "src")
+ if( !file.exists( src )){
+ dir.create( src )
+ }
+ skeleton <- system.file( "skeleton", package = "RcppEigen" )
+ Makevars <- file.path( src, "Makevars" )
+ if( !file.exists( Makevars ) ){
+ file.copy( file.path( skeleton, "Makevars" ), Makevars )
+ message( " >> added Makevars file with Rcpp settings" )
+ }
+
+ Makevars.win <- file.path( src, "Makevars.win" )
+ if( !file.exists( Makevars.win ) ){
+ file.copy( file.path( skeleton, "Makevars.win" ), Makevars.win )
+ message( " >> added Makevars.win file with RcppEigen settings" )
+ }
+
+ if( example_code ){
+ header <- readLines( file.path( skeleton, "rcppeigen_hello_world.h" ) )
+ header <- gsub( "@PKG@", name, header, fixed = TRUE )
+ writeLines( header , file.path( src, "rcppeigen_hello_world.h" ) )
+ message( " >> added example header file using Rcpp/RcppEigen")
+
+ file.copy( file.path( skeleton, "rcppeigen_hello_world.cpp" ), src )
+ message( " >> added example src file using armadillo classes")
+
+ rcode <- readLines( file.path( skeleton, "rcppeigen_hello_world.R" ) )
+ rcode <- gsub( "@PKG@", name, rcode, fixed = TRUE )
+ writeLines( rcode , file.path( root, "R", "rcppeigen_hello_world.R" ) )
+ message( " >> added example R file calling the C++ example")
+ }
+ if( fake ){
+ rm( "Rcpp.fake.fun", envir = env )
+ unlink( file.path( root, "R" , "Rcpp.fake.fun.R" ) )
+ unlink( file.path( root, "man", "Rcpp.fake.fun.Rd" ) )
+
+ }
+
+ invisible( NULL )
+}
+
Added: pkg/RcppEigen/inst/skeleton/Makevars
===================================================================
--- pkg/RcppEigen/inst/skeleton/Makevars (rev 0)
+++ pkg/RcppEigen/inst/skeleton/Makevars 2011-06-15 19:04:15 UTC (rev 3081)
@@ -0,0 +1,3 @@
+## Use the R_HOME indirection to support installations of multiple R version
+PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"`
+
Added: pkg/RcppEigen/inst/skeleton/Makevars.win
===================================================================
--- pkg/RcppEigen/inst/skeleton/Makevars.win (rev 0)
+++ pkg/RcppEigen/inst/skeleton/Makevars.win 2011-06-15 19:04:15 UTC (rev 3081)
@@ -0,0 +1,5 @@
+
+## This assume that we can call Rscript to ask Rcpp about its locations
+## Use the R_HOME indirection to support installations of multiple R version
+PKG_LIBS = $(shell $(R_HOME)/bin/Rscript.exe -e "Rcpp:::LdFlags()")
+
Added: pkg/RcppEigen/inst/skeleton/rcppeigen_hello_world.R
===================================================================
--- pkg/RcppEigen/inst/skeleton/rcppeigen_hello_world.R (rev 0)
+++ pkg/RcppEigen/inst/skeleton/rcppeigen_hello_world.R 2011-06-15 19:04:15 UTC (rev 3081)
@@ -0,0 +1,5 @@
+
+rcppeigen_hello_world <- function(){
+ .Call( "rcppeigen_hello_world", PACKAGE = "@PKG@" )
+}
+
Added: pkg/RcppEigen/inst/skeleton/rcppeigen_hello_world.cpp
===================================================================
--- pkg/RcppEigen/inst/skeleton/rcppeigen_hello_world.cpp (rev 0)
+++ pkg/RcppEigen/inst/skeleton/rcppeigen_hello_world.cpp 2011-06-15 19:04:15 UTC (rev 3081)
@@ -0,0 +1,16 @@
+#include "rcppeigen_hello_world.h"
+
+using namespace Rcpp ;
+
+SEXP rcppeigen_hello_world(){
+
+ Eigen::MatrixXd m1 = Eigen::MatrixXd::Identity( 3, 3 ) ;
+ Eigen::MatrixXd m2 = Eigen::MatrixXd::Random( 3, 3 ) ;
+ // need more flexible wrap methods
+ Eigen::MatrixXd comb = m1 + 3 * (m1 + m2);
+
+ return List::create(_["m1"] = m1,
+ _["m2"] = m2,
+ _["comb"] = comb);
+}
+
Added: pkg/RcppEigen/inst/skeleton/rcppeigen_hello_world.h
===================================================================
--- pkg/RcppEigen/inst/skeleton/rcppeigen_hello_world.h (rev 0)
+++ pkg/RcppEigen/inst/skeleton/rcppeigen_hello_world.h 2011-06-15 19:04:15 UTC (rev 3081)
@@ -0,0 +1,8 @@
+#ifndef _ at PKG@_RCPP_HELLO_WORLD_H
+#define _ at PKG@_RCPP_HELLO_WORLD_H
+
+#include <RcppEigen.h>
+
+RcppExport SEXP rcppeigen_hello_world() ;
+
+#endif
Added: pkg/RcppEigen/man/RcppEigen.package.skeleton.Rd
===================================================================
--- pkg/RcppEigen/man/RcppEigen.package.skeleton.Rd (rev 0)
+++ pkg/RcppEigen/man/RcppEigen.package.skeleton.Rd 2011-06-15 19:04:15 UTC (rev 3081)
@@ -0,0 +1,69 @@
+\name{RcppEigen.package.skeleton}
+\alias{RcppEigen.package.skeleton}
+\title{
+Create a skeleton for a new package that intends to use RcppEigen
+}
+\description{
+ \code{RcppEigen.package.skeleton} automates the creation of
+ a new source package that intends to use features of RcppEigen.
+
+ It is based on the \link[utils]{package.skeleton} function
+ which it executes first.
+}
+\usage{
+RcppEigen.package.skeleton(name = "anRpackage", list = character(),
+ environment = .GlobalEnv, path = ".", force = FALSE, namespace = TRUE,
+ code_files = character(), example_code = TRUE)
+}
+\arguments{
+ \item{name}{See \link[utils]{package.skeleton}}
+ \item{list}{See \link[utils]{package.skeleton}}
+ \item{environment}{See \link[utils]{package.skeleton}}
+ \item{path}{See \link[utils]{package.skeleton}}
+ \item{force}{See \link[utils]{package.skeleton}}
+ \item{namespace}{See \link[utils]{package.skeleton}}
+ \item{code_files}{See \link[utils]{package.skeleton}}
+ \item{example_code}{If TRUE, example C++ code using RcppEigen is added to the package}
+}
+\details{
+ In addition to \link[utils]{package.skeleton} :
+
+ The \samp{DESCRIPTION} file gains a Depends line requesting that
+ the package depends on Rcpp and RcppEigen and
+ a LinkingTo line so that the package finds Rcpp and RcppEigen header files.
+
+ The \samp{NAMESPACE}, if any, gains a \code{useDynLib} directive.
+
+ The \samp{src} directory is created if it does not exists and
+ a \samp{Makevars} file is added setting the environment variable
+ \samp{PKG_LIBS} to accomodate the necessary flags
+ to link with the Rcpp library.
+
+ If the \code{example_code} argument is set to \code{TRUE},
+ example files \samp{rcppeigen_hello_world.h} and \samp{rcppeigen_hello_world.cpp}
+ are also created in the \samp{src}. An R file \samp{rcppeigen_hello_world.R} is
+ expanded in the \samp{R} directory, the \code{rcppeigen_hello_world} function
+ defined in this files makes use of the C++ function \samp{rcppeigen_hello_world}
+ defined in the C++ file. These files are given as an example and should
+ eventually by removed from the generated package.
+}
+\value{
+Nothing, used for its side effects
+}
+\seealso{
+\link[utils]{package.skeleton}
+}
+\references{
+Read the \emph{Writing R Extensions} manual for more details.
+
+Once you have created a \emph{source} package you need to install it:
+see the \emph{R Installation and Administration} manual,
+\code{\link{INSTALL}} and \code{\link{install.packages}}.
+}
+\examples{
+\dontrun{
+RcppEigen.package.skeleton( "foobar" )
+}
+}
+\keyword{ programming }
+
More information about the Rcpp-commits
mailing list