Csnippet {pomp} | R Documentation

## C snippets

### Description

Accelerating computations through inline snippets of C code

### Usage

    Csnippet(text)

### Arguments

`text` | character; text written in the C language

### Details

pomp provides a facility whereby users can define their model's components using inline C code. C snippets are written to a C file, by default located in the R session's temporary directory, which is then compiled (via `R CMD SHLIB`) into a dynamically loadable shared object file. This is then loaded as needed.

### Note to Windows and Mac users

By default, your R installation may not support `R CMD SHLIB`. The package website contains installation instructions that explain how to enable this powerful feature of R.

### General rules for writing C snippets

In writing a C snippet one must bear in mind both the goal of the snippet, i.e., what computation it is intended to perform, and the context in which it will be executed. These are explained here in the form of general rules. Additional specific rules apply according to the function of the particular C snippet. Illustrative examples are given in the tutorials on the package website.

1. C snippets must be valid C. They will embedded verbatim in a template file which will then be compiled by a call to `R CMD SHLIB`. If the resulting file does not compile, an error message will be generated. Compiler messages will be displayed, but no attempt will be made by pomp to interpret them. Typically, compilation errors are due to either invalid C syntax or undeclared variables.

2. State variables, parameters, observables, and covariates must be left undeclared within the snippet. State variables and parameters are declared via the `statenames` or `paramnames` arguments to `pomp`, respectively. Compiler errors that complain about undeclared state variables or parameters are usually due to failure to declare these in `statenames` or `paramnames`, as appropriate.

3. A C snippet can declare local variables. Be careful not to use names that match those of state variables, observables, or parameters. One must never declare state variables, observables, covariates, or parameters within a C snippet.

4. Names of observables must match the names given given in the data. They must be referred to in measurement model C snippets (`rmeasure` and `dmeasure`) by those names.

5. If the ‘pomp’ object contains a table of covariates (see above), then the variables in the covariate table will be available, by their names, in the context within which the C snippet is executed.

6. Because the dot ‘.’ has syntactic meaning in C, R variables with names containing dots (‘.’) are replaced in the C codes by variable names in which all dots have been replaced by underscores (‘_’).

7. The headers ‘R.h’ and ‘Rmath.h’, provided with R, will be included in the generated C file, making all of the R C API available for use in the C snippet. This makes a great many useful functions available, including all of R's statistical distribution functions.

8. The header ‘pomp.h’, provided with pomp, will also be included, making all of the pomp C API available for use in every C snippet.

9. Snippets of C code passed to the `globals` argument of `pomp` will be included at the head of the generated C file. This can be used to declare global variables, define useful functions, and include arbitrary header files.

10. INCLUDE INFORMATION ABOUT LINKING TO PRECOMPILED LIBRARIES!

### See Also

Other information on model implementation: `accumulators`, `covariate_table`, `distributions`, `dmeasure_spec`, `dprocess_spec`, `parameter_trans`, `pomp-package`, `prior_spec`, `rinit_spec`, `rmeasure_spec`, `rprocess_spec`, `skeleton_spec`, `transformations`, `userdata`

[Package pomp version 2.3 Index]