chain.write {tripEstimation}R Documentation

~~function to do ... ~~

Description

~~ A concise (1-5 lines) description of what the function does. ~~

Usage

chain.write(filename, A, append = FALSE)

Arguments

filename ~~Describe filename here~~
A ~~Describe A here~~
append ~~Describe append here~~

Details

~~ If necessary, more details than the description above ~~

Value

~Describe the value returned If it is a LIST, use

comp1 Description of 'comp1'
comp2 Description of 'comp2'

...

Warning

....

Note

~~further notes~~

~Make other sections like Warning with section{Warning }{....} ~

Author(s)

~~who you are~~

References

~put references to the literature/web site here ~

See Also

~~objects to See Also as help, ~~~

Examples

##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--    or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function(filename,A,append=FALSE) {
  A <- as.array(A)
  if(!append) {
    ## Open a binary connection for writing, truncating or
    ## creating the file if necessary
    con <- file(filename,open="wb")
    ## Write array dimensions
    writeBin(as.integer(dim(A)),con)
    ## Write the data and close
    writeBin(as.double(A),con)
    close(con)
  } else {
    ## Open a binary connection for appending
    con <- file(filename,open="r+b")
    ## Read the dimensions of the array
    seek(con,0,origin="start",rw="r")
    dm <- readBin(con,"integer",3)
    ## Check the data to append has compatible dimensions
    if(length(dm)!=length(dim(A)) || any(dm[-3]!=dim(A)[-3]))
      stop("Incompatible dimensions for appending\n")
    ## Append the new data
    seek(con,0,origin="end",rw="w")
    writeBin(as.double(A),con)
    ## Write new dimensions and close
    dm[3] <- dm[3]+dim(A)[3]
    seek(con,0,origin="start",rw="w")
    writeBin(as.integer(dm),con)
    close(con)
  }
  }

[Package tripEstimation version 0.0-24 Index]