list.dump.format: Conversion Between a Named List and a Character String in the...

Description Usage Arguments Details Value See Also Examples

Description

Convert a named list of numeric vector(s) or array(s) of data or initial values to a character string in the correct format to be read directly by JAGS as either data or initial values.

Usage

1
2
3
4
	dump.format(namedlist=list(), checkvalid=TRUE,
		convertfactors = TRUE)
	
	list.format(data=character(), checkvalid=TRUE)

Arguments

namedlist

a named list of numeric or integer (or something that can be coerced to numeric) vectors, matrices or arrays. The name of each list item will be used as the name of the resulting dump.format variables.

data

a character string in the R dump format, such as that produced by dump.format.

checkvalid

option to ensure that the object returned from the function does not contain any values that would be invalid for import into JAGS, such as Inf, -Inf or character values etc.

convertfactors

option to automatically convert any factor variables to numeric (otherwise the presence of factors will create an error if checkvalid==TRUE).

Details

The 'dump.format' function creates a character string of the supplied variables in the same way that dump() would, except that the result is returned as a character string rather than written to file. Additionally, dump.format() will look for any variable with the name '.RNG.name' and double quote the value if not already double quoted (to ensure compatibility with JAGS).

Value

Either a character string in the R dump format (for dump.format), or a named list (for list.format).

See Also

run.jags, dump

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# A named list:
namedlist1 <- list(N=10, Count=c(4,2,7,0,6,9,1,4,12,1))

# Conver to a character vector:
chardata <- dump.format(namedlist1)

# And back to a named list:
namedlist2 <- list.format(chardata)

# These should be the same:
stopifnot(identical(namedlist1, namedlist2))

runjags documentation built on March 26, 2020, 9:24 p.m.