write_omx: Function to write OMX matrix data

View source: R/read_write_omx.R

write_omxR Documentation

Function to write OMX matrix data

Description

This function writes OMX matrix data. A full matrix can be written or just portions of an existing matrix. It allows overwriting existing matrix values, but only if the "Replace" argument is set to TRUE. If only portions of the matrix are to be written to, the full matrix must already exist.

Usage

write_omx(
  matrix,
  file,
  name,
  row_index = NULL,
  col_index = NULL,
  na_value = -1,
  replace = FALSE,
  description = ""
)

Arguments

matrix

Matrix object to be stored.

file

Full path name of the OMX file to store the matrix in. If this is a new matrix file, see create_omx.

name

Name of the matrix in the OMX object.

row_index

An integer vector indicating the rows represented by matrix. Defaults to NULL, meaning that all rows are written (and nrow(matrix) is the number of rows in the matrix).

col_index

The precise corrolary to row_index, for columns.

na_value

The value representing NA values in the matrix. Defaults to -1

replace

If the named object already exists in file, should it be replaced? Defaults to FALSE.

description

(Optional) description of matrix contents.

Value

Write function return code; 0 if successful.

Examples

omxfile <- tempfile(fileext = ".omx")
create_omx(omxfile, 10, 10)
trips <- matrix(rnorm(n = 10^2, 200, 50),   
                nrow = 10, ncol = 10)
write_omx(matrix = trips, omxfile, "trips",  description = "Total Trips")


gregmacfarlane/omxr documentation built on May 7, 2022, 11:42 a.m.