comparison R/rdyncall/man/utils.Rd @ 0:0cfcc391201f

initial from svn dyncall-1745
author Daniel Adler
date Thu, 19 Mar 2015 22:26:28 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0cfcc391201f
1 \name{utils}
2 \alias{is.nullptr}
3 \alias{as.extptr}
4 \alias{is.externalptr}
5 \alias{floatraw}
6 \alias{as.floatraw}
7 \alias{floatraw2numeric}
8 \alias{ptr2str}
9 \alias{strarrayptr}
10 \alias{strptr}
11 \alias{offsetPtr}
12 \title{Utility functions for working with foreign C data types}
13 \description{Functions for low-level operations on C pointers as well as
14 helper functions and objects to handle C \code{float} arrays and strings.}
15 \usage{
16 is.nullptr(x)
17 as.extptr(x)
18 is.externalptr(x)
19 floatraw(n)
20 as.floatraw(x)
21 floatraw2numeric(x)
22 ptr2str(x)
23 strarrayptr(x)
24 strptr(x)
25 offsetPtr(x, offset)
26 }
27 \arguments{
28 \item{x}{an R object.}
29 \item{n}{number of elements to allocate.}
30 \item{offset}{a offset given in bytes.}
31 }
32 \details{
33
34 \code{is.nullptr} tests if the external pointer given by \code{x} represents a C \code{NULL} pointer.
35
36 \code{as.extptr} returns an external pointer to the data area of atomic
37 vector given by \code{x}. The external pointer holds an additional reference
38 to the \code{x} R object to prevent it from garbage collection.
39
40 \code{is.externalptr} tests if the object given by \code{x} is an external pointer.
41
42 \code{floatraw} creates an array with a capacity to store \code{n} single-precision C \code{float} values.
43 The array is implemented via a \code{\link[base]{raw}} vector.
44
45 \code{as.floatraw} coerces a numeric vector into a single-precision C \code{float} vector.
46 Values given by \code{x} are converted to C \code{float} values and stored in the R raw vector via \code{.pack}.
47 This function is useful when calling foreign functions that expeect a C \code{float} pointer via \code{\link{.dyncall}}.
48
49 \code{floatraw2numeric} coerces a C \code{float} (raw) vector to a numeric vector.
50
51 \code{ptr2str}, \code{strarrayptr}, \code{strptr} are currently experimental.
52
53 \code{offsetPtr} creates a new external pointer pointing to \code{x} plus the byte \code{offset}.
54 If \code{x} is given as an external pointer, the address is increased by the \code{offset},
55 or, if \code{x} is given as a atomic vector, the address of the data (pointing to offset zero) is taken as basis
56 and increased by the \code{offset}.
57 The returned external pointer is protected (as offered by the C function \code{R_MakeExternalPtr}) by the external pointer \code{x}.
58 }
59 \value{
60 A logical value is returned by \code{is.nullptr} and \code{is.externalptr}.
61 \code{as.extptr} returns an external pointer value.
62 \code{floatraw} and \code{as.floatraw} return an atomic vector of type \code{raw}
63 tagged with class \code{'floatraw'}.
64 \code{floatraw2numeric} returns a \code{numeric} atomic vector.
65 }
66 \keyword{programming}
67 \keyword{interface}