Cfrag.list {PortfolioProbe} | R Documentation

## Write a Fragment of a C Program

### Description

Writes either the C declaration of items in a list, or initializes them with the contents of the list.

### Usage

    Cfrag.list(x, file = NULL,  item.num = c(3, 10, 5),
            indent = c("\t", "\t\t"), declaration.only = FALSE,
            long = FALSE, append = FALSE)

### Arguments

`x` | required. A list with names.
`file` | either `NULL` or a character string. If `NULL` (or an empty string), then a vector of characters is returned.
`item.num` | length three vector giving the number of items per line for doubles, integers and characters.
`indent` | length two vector giving the amount to indent declarations and the items in the initialization.
`declaration.only` | logical flag. If `TRUE`, then the variables are declared but not given initial values.
`long` | logical flag. If `TRUE`, then integers are declared to be "long". If `FALSE`, then integers are declared to be "int".
`append` | logical flag. If `TRUE`, then the file is appended to; otherwise it is overwritten if it exists.

### Value

if `file` is a non-empty character string, then the name of the file that is written. Otherwise, a character vector of the declarations – each element representing a different line.

### Side Effects

if `file` is a non-empty character string, then the file is created, overwritten or appended.

### Details

The type to declare is dependent on the storage mode of the component of `x`. You may need to coerce components to get them to be declared the correct type.

### Revision

This help was last revised 2009 September 21.

### See Also

`.C`, `storage.mode`, `as.double`, `as.integer`, `as.character`, `cat`.

### Examples

    test.list <- list(adoub=as.double(rnorm(20)), anint=as.integer(92:109),
            achar=c("aaa", "bbbb", "ccccc"))

    Cfrag.list(test.list, file="test.c")

    Cfrag.list(test.list[1], file="test.c", dec=TRUE)
    Cfrag.list(test.list[-1], file="test.c", dec=FALSE, append=TRUE)

[Package PortfolioProbe version 1.02 Index]