Skip to content

Commit 0db9886

Browse files
committed
Rename classModule to exposeClass; recommend it from setRcppClass.Rd
1 parent d5b9363 commit 0db9886

File tree

5 files changed

+44
-33
lines changed

5 files changed

+44
-33
lines changed

ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2013-10-06 John M Chambers <jmc@r-project.org>
2+
3+
* NAMESPACE: change classModule to expose Class
4+
* R/classModule.R: delete
5+
* man/classModule.Rd: delete
6+
* R/exposeClass.R: add
7+
* man/exposeClass.Rd: add
8+
* man/setRcppClass.Rd: update, clarify, recommend exposeClass()
9+
110
2013-10-03 John M Chambers <jmc@r-project.org>
211

312
* R/classModule.R: new function to write module file for class

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export(Module,
2020
setRcppClass,
2121
loadRcppClass,
2222
loadModule,
23-
classModule,
2423
cppFunction,
24+
exposeClass,
2525
evalCpp,
2626
sourceCpp,
2727
compileAttributes,

R/classModule.R renamed to R/exposeClass.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
paste0(ns, "::",mName)
5454
}
5555

56-
classModule <- function(class, constructors, fields, methods,
56+
exposeClass <- function(class, constructors, fields, methods,
5757
file = paste0(CppClass, "Module.cpp"),
5858
header = character(),
5959
module = paste0("class_",class), CppClass = class,
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
\name{classModule}
2-
\alias{classModule}
1+
\name{exposeClass}
2+
\alias{exposeClass}
33
\title{
44
Create an Rcpp Module to Expose a C++ Class in R
55
}
66
\description{
77
The arguments specify a C++ class and some combination of
88
constructors, fields and methods to be shared with \R by creating a
99
corresponding reference class in \R.
10-
The information needed in the call to \code{classModule()} is the
10+
The information needed in the call to \code{exposeClass()} is the
1111
simplest possible in order to create a C++ module for the class; for
1212
example, fields and methods in this class need only be identified by
1313
their name.
@@ -20,7 +20,7 @@ class.
2020
}
2121

2222
\usage{
23-
classModule(class, constructors = , fields = , methods = , file = ,
23+
exposeClass(class, constructors = , fields = , methods = , file = ,
2424
header = , module = , CppClass = class, readOnly = , rename = ,
2525
Rfile = TRUE)
2626
}
@@ -97,16 +97,16 @@ information in the C++ class supplied. This file is intended to be
9797
part of the C++ source for an \R package. The file only needs to
9898
modified when the information changes, either because the class has
9999
changed or because you want to expose different information to \R. In
100-
that case you can either recall \code{classModule()} or edit the C++
100+
that case you can either recall \code{exposeClass()} or edit the C++
101101
file created.
102102

103103
The Rcpp Module mechanism has a number of other optional techniques,
104-
not covered by \code{classModule()}. These should be entered into the
104+
not covered by \code{exposeClass()}. These should be entered into the
105105
C++ file created. See the \dQuote{rcpp-modules} vignette with the
106106
package for current possibilities.
107107

108108
For fields and methods specified directly in the C++ class,
109-
the fields and method arguments to \code{classModule()} are character vectors naming the
109+
the fields and method arguments to \code{exposeClass()} are character vectors naming the
110110
corresponding members of the class. For module construction, the
111111
data types of directly specified fields and of the arguments for the methods are not
112112
needed.
@@ -128,7 +128,7 @@ An indirect mechanism is used, generating free functions in C++ to
128128
expose the inherited members in \R.
129129

130130
This mechanism requires data type information in the call to
131-
\code{classModule()}.
131+
\code{exposeClass()}.
132132
This is provided by naming the corresponding element of the
133133
\code{fields} or \code{methods} argument with the name of the member.
134134
The actual element of the \code{fields} argument is then the single
@@ -158,7 +158,7 @@ in the package.
158158
\examples{
159159
\dontrun{
160160
### Given the following C++ class, defined in file PopBD.h,
161-
### the call to classModule() shown below will write a file
161+
### the call to exposeClass() shown below will write a file
162162
### src/PopBDModule.cpp containing a corresponding module definition.
163163
### class PopBD {
164164
### public:
@@ -178,7 +178,7 @@ in the package.
178178
### The call below exposes the lineage and size fields, read-only,
179179
### and the evolve() method.
180180

181-
classModule("PopBD",
181+
exposeClass("PopBD",
182182
constructors =
183183
list("", c("NumericVector", "NumericVector")),
184184
fields = c("lineage", "size"),
@@ -191,7 +191,7 @@ classModule("PopBD",
191191
### constructors as the previous class.
192192
### To expose the table() method, and the inherited evolve() method and size field:
193193

194-
classModule("PopCount",
194+
exposeClass("PopCount",
195195
constructors =
196196
list("", c("NumericVector", "NumericVector")),
197197
fields = c(size = "std::vector<long>"),

man/setRcppClass.Rd

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
Create a Class Extending a C++ Class
77
}
88
\description{
9-
A class is defined that includes the fields and methods of a C++ class
10-
defined, usually in this package. For most applications, it is
11-
recommended to call
12-
\code{\link{classModule}()} to write files in the package with a call to \code{setRcppClass()} and the
13-
C++ module code required. See Details.
9+
These routines create a class definition in \R for an exposed C++
10+
class, setting up and executing a load action to incorporate the C++
11+
pointer information.
12+
Neither function should normally need to be called directly; for most applications,
13+
a call to
14+
\code{\link{exposeClass}()} will create both C++ and \R code files to
15+
expose the C++ class.
1416
}
1517
\usage{
1618
setRcppClass(Class, CppClass = , module = , fields = list(), contains = ,
@@ -33,12 +35,14 @@ The Rcpp module in which the class is defined. The module does not
3335
have to be loaded separately; \code{setRcppClass()} will arrange to
3436
load the module. By default, \code{"class_"} followed by the C++ class
3537
name.
38+
39+
If \code{\link{exposeClass}()} has been called, the necessary module
40+
code will have been written in the \code{src} directory of the package.
3641
}
3742
\item{fields, contains, methods}{
3843
Additional fields, superclasses and method definitions in \R{} that
3944
extend the C++ class. These arguments are passed on to
4045
\code{\link{setRefClass}()}.
41-
See Details for recommendations.
4246
}
4347
\item{saveAs}{
4448
Save a generator object for the class in the package's namespace under
@@ -67,21 +71,12 @@ Arguments, if any, to pass on to \code{\link{setRefClass}()}.
6771
}
6872
\details{
6973
The call to these functions normally appears in the source code for a
70-
package.
71-
It generates a load action that loads the specified module and
72-
extracts the C++ class definition specified.
74+
package; in particular, a call is written in an \R source file when
75+
\code{\link{exposeClass}()} is called.
7376
74-
\R{} code can define new fields and methods for the class, typically
75-
as prototypes for possible future C++ implementation.
77+
\R{} code for this class or (preferably) a subclass can define new fields and methods for the class.
7678
Methods for the \R{} class can refer to methods and fields defined in
77-
C++ for the C++ class.
78-
These will be mapped into the C++ equivalents by \R{} code generated
79-
by \code{setRcppClass}.
80-
The C++ code may not deal as well as \R{} with incompatible
81-
argument types and lengths.
82-
Segmentation faults are a definite possibility.
83-
If that's a problem, you should define methods in \R{} that check for
84-
legal data types and values.
79+
C++ for the C++ class, if those have been exposed.
8580
8681
The fields and methods defined can
8782
include overriding C++ fields or methods.
@@ -93,7 +88,14 @@ Otherwise, the C++ code will continue to use the old C++ definition.
9388
9489
}
9590
\value{
96-
A generator for the new class.
91+
At load time, a generator for the new class is created and stored
92+
according to the \code{saveAs} argument, typically under the name of
93+
the class.
94+
95+
The value returned at installation time is a dummy. Future revisions
96+
of the function may allow us to return a valid generator at install
97+
time. We recommend using the standard style of assigning the value
98+
to the name of the class, as one would do with \code{\link{setRefClass}}.
9799
}
98100
\author{
99101
John Chambers

0 commit comments

Comments
 (0)