Skip to content

Commit b8b9c37

Browse files
committed
update RcppEigen.package.skeleton() (closes #16)
- now uses pkgKitten - new file inst/skeleton/rcppeigen_hello_world.Rd - also minor update to Makevars{,.win} - bumped Version: and Date:
1 parent 88c61ca commit b8b9c37

5 files changed

Lines changed: 85 additions & 24 deletions

File tree

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: RcppEigen
22
Type: Package
33
Title: Rcpp integration for the Eigen templated linear algebra library.
4-
Version: 0.3.2.3.0
5-
Date: 2014-12-22
4+
Version: 0.3.2.3.1
5+
Date: 2015-02-23
66
Author: Douglas Bates, Romain Francois and Dirk Eddelbuettel;
77
the authors of Eigen for the included version of Eigen
88
Maintainer: Dirk Eddelbuettel <edd@debian.org>
@@ -28,5 +28,5 @@ Depends: R (>= 2.15.1)
2828
LazyLoad: yes
2929
LinkingTo: Rcpp
3030
Imports: Matrix (>= 1.1-0), Rcpp (>= 0.11.0)
31-
Suggests: inline, RUnit
31+
Suggests: inline, RUnit, pkgKitten
3232
URL: http://eigen.tuxfamily.org

R/RcppEigen.package.skeleton.R

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## RcppEigen.package.skeleton.R: makes a skeleton for a package that wants to use RcppEigen
22
##
3-
## Copyright (C) 2011 - 2014 Douglas Bates, Dirk Eddelbuettel and Romain Francois
3+
## Copyright (C) 2011 - 2015 Douglas Bates, Dirk Eddelbuettel and Romain Francois
44
##
55
## This file is part of RcppEigen.
66
##
@@ -31,21 +31,27 @@ RcppEigen.package.skeleton <- function(name= "anRpackage", list = character(),
3131
} else {
3232
fake <- FALSE
3333
}
34-
34+
35+
haveKitten <- requireNamespace("pkgKitten", quietly=TRUE, character.only=TRUE)
36+
skelFunUsed <- ifelse(haveKitten, "kitten", "package.skeleton")
37+
message("\nCalling ", skelFunUsed, " to create basic package.")
38+
3539
## first let the traditional version do its business
3640
call <- match.call()
37-
call[[1]] <- as.name("package.skeleton")
38-
if ("example_code" %in% names(call)) {
39-
## remove the example_code argument
40-
call[["example_code"]] <- NULL
41-
}
42-
if (fake) {
43-
call[["list"]] <- "Rcpp.fake.fun"
41+
call[[1]] <- if (haveKitten) as.name("kitten") else as.name("package.skeleton")
42+
if (! haveKitten) { # in the package.skeleton() case
43+
if ("example_code" %in% names(call)) {
44+
call[["example_code"]] <- NULL # remove the example_code argument
45+
}
46+
if (fake) {
47+
call[["list"]] <- "Rcpp.fake.fun"
48+
}
4449
}
4550

46-
tryCatch(eval(call, envir = env), error = function(e) {
47-
stop("error while calling `package.skeleton`")
48-
})
51+
tryCatch(eval(call, envir = env),
52+
error = function(e) {
53+
stop(paste("error while calling `", skelFunUsed, "`", sep=""))
54+
})
4955

5056
message("\nAdding RcppEigen settings")
5157

@@ -65,7 +71,7 @@ RcppEigen.package.skeleton <- function(name= "anRpackage", list = character(),
6571
message(" >> added LinkingTo: Rcpp, RcppEigen")
6672
}
6773

68-
## if there is a NAMESPACE, add a useDynLib
74+
## add a useDynLib to NAMESPACE,
6975
NAMESPACE <- file.path(root, "NAMESPACE")
7076
lines <- readLines(NAMESPACE)
7177
if (! grepl("useDynLib", lines)) {
@@ -74,30 +80,36 @@ RcppEigen.package.skeleton <- function(name= "anRpackage", list = character(),
7480
"importFrom(Rcpp, evalCpp)", ## ensures Rcpp instantiation
7581
lines)
7682
writeLines(lines, con = NAMESPACE)
77-
message(" >> added useDynLib directive to NAMESPACE")
83+
message(" >> added useDynLib and importFrom directives to NAMESPACE")
7884
}
7985

8086
## lay things out in the src directory
8187
src <- file.path(root, "src")
8288
if (!file.exists(src)) {
8389
dir.create(src)
8490
}
91+
man <- file.path(root, "man")
92+
if (!file.exists(man)) {
93+
dir.create(man)
94+
}
8595
skeleton <- system.file("skeleton", package = "RcppEigen")
8696
Makevars <- file.path(src, "Makevars")
8797
if (!file.exists(Makevars)) {
8898
file.copy(file.path(skeleton, "Makevars"), Makevars)
89-
message(" >> added Makevars file")
99+
message(" >> added Makevars file with RcppEigen settings")
90100
}
91101

92102
Makevars.win <- file.path(src, "Makevars.win")
93103
if (!file.exists(Makevars.win)) {
94104
file.copy(file.path(skeleton, "Makevars.win"), Makevars.win)
95-
message(" >> added Makevars.win file")
105+
message(" >> added Makevars.win file with RcppEigen settings")
96106
}
97107

98108
if (example_code) {
99109
file.copy(file.path(skeleton, "rcppeigen_hello_world.cpp"), src)
100110
message(" >> added example src file using Eigen classes")
111+
file.copy(file.path(skeleton, "rcppeigen_hello_world.Rd"), man)
112+
message(" >> added example Rd file for using Eigen classes")
101113

102114
Rcpp::compileAttributes(root)
103115
message(" >> invoked Rcpp::compileAttributes to create wrappers")
@@ -107,7 +119,6 @@ RcppEigen.package.skeleton <- function(name= "anRpackage", list = character(),
107119
rm("Rcpp.fake.fun", envir = env)
108120
unlink(file.path(root, "R" , "Rcpp.fake.fun.R"))
109121
unlink(file.path(root, "man", "Rcpp.fake.fun.Rd"))
110-
111122
}
112123

113124
invisible(NULL)

inst/skeleton/Makevars

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#PKG_LIBS =
44

55
## With R 3.1.0 or later, you can uncomment the following line to tell R to
6-
## enable compilation with C++11 (where available)
7-
#USE_CXX1X =
6+
## enable compilation with C++11 (or even C++14) where available
7+
#CXX_STD = CXX11

inst/skeleton/Makevars.win

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#PKG_LIBS =
44

55
## With R 3.1.0 or later, you can uncomment the following line to tell R to
6-
## enable compilation with C++11 (where available)
7-
#USE_CXX1X =
6+
## enable compilation with C++11 (or even C++14) where available
7+
#CXX_STD = CXX11
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
\name{RcppEigen-Functions}
2+
\alias{rcppeigen_hello_world}
3+
\alias{rcppeigen_innerproduct}
4+
\alias{rcppeigen_outerproduct}
5+
\alias{rcppeigen_bothproducts}
6+
\title{Set of functions in example RcppEigen package}
7+
\description{
8+
These four functions are created when
9+
\code{RcppEigen.package.skeleton()} is invoked to create a
10+
skeleton packages.
11+
}
12+
\usage{
13+
rcppeigen_hello_world()
14+
rcppeigen_outerproduct(x)
15+
rcppeigen_innerproduct(x)
16+
rcppeigen_bothproducts(x)
17+
}
18+
\arguments{
19+
\item{x}{a numeric vector}
20+
}
21+
\value{
22+
\code{rcppeigen_hello_world()} does not return a value, but displays a
23+
message to the console.
24+
25+
\code{rcppeigen_outerproduct()} returns a numeric matrix computed as the
26+
outer (vector) product of \code{x}.
27+
28+
\code{rcppeigen_innerproduct()} returns a double computer as the inner
29+
(vector) product of \code{x}.
30+
31+
\code{rcppeigen_bothproducts()} returns a list with both the outer and
32+
inner products.
33+
34+
}
35+
\details{
36+
These are example functions which should be largely
37+
self-explanatory. Their main benefit is to demonstrate how to write a
38+
function using the Eigen C++ classes, and to have to such a
39+
function accessible from R.
40+
}
41+
\references{
42+
See the documentation for Eigen, and RcppEigen, for more details.
43+
}
44+
\examples{
45+
x <- sqrt(1:4)
46+
rcppeigen_innerproduct(x)
47+
rcppeigen_outerproduct(x)
48+
}
49+
\author{Dirk Eddelbuettel}
50+

0 commit comments

Comments
 (0)