MuGen
Multitrait genetics
Functions
GSLRIO.cpp File Reference

R interface for GSL binary file format. More...

#include <R.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>
Include dependency graph for GSLRIO.cpp:

Functions

void GSLmatSave (const char **fileNam, const double *vec, const int *nRows, const int *nCols)
 Save a double-precision matrix. More...
 
void GSLvecSaveInt (const char **fileNam, const int *vec, const int *len)
 Save a vector of integers. More...
 
void GSLvecSave (const char **fileNam, const double *vec, const int *len)
 Save a double-precision vector. More...
 
void GSLvecAppend (const char **fileNam, const double *vec, const int *len)
 Appending a double-precision vector to an existing file. More...
 
void GSLiVecLoad (const char **fileNam, const int *len, int *arr)
 Read a vector of integers. More...
 
void GSLmatLoad (const char **fileNam, const int *nRows, const int *nCols, double *arr)
 Read a double-precision array or matrix. More...
 

Detailed Description

R interface for GSL binary file format.

Author
Anthony J. Greenberg
Version
0.9.1

Functions to read and write binary files saved in GSL binary format from R.

To compile, run on command line:

R CMD SHLIB GSLRIO.cpp -lgsl -O3 -DHAVE_INLINE -DGSL_RANGE_CHECK_OFF

and put the resulting GSLRIO.o where it can be found by dyn.load() in R. The functions are then ready to use with the .C() command.

Note
To pass double-quoted strings from .C(), the corresponding arguments (here they are file names) must be in the form **fileNam.

Function Documentation

◆ GSLiVecLoad()

void GSLiVecLoad ( const char **  fileNam,
const int *  len,
int *  arr 
)

Read a vector of integers.

Reading a file into an array of integers.

Warning
While file existence is checked, there currently is no way to check file size. If the file is too small to hold an array of integers of the required length, the function will crash and likely take the R session with it.
Parameters
[in]char**output file name
[in]int*pointer to array length
[out]int*array of integers to be passed to R

◆ GSLmatLoad()

void GSLmatLoad ( const char **  fileNam,
const int *  nRows,
const int *  nCols,
double *  arr 
)

Read a double-precision array or matrix.

Reads a double-precision array (vector) or matrix. If a vector is desired, one of the dimensions should be set to one. The matrix is stored by row, so make sure to use matrix(..., byrow = T) in the R code.

Warning
While file existence is checked, there currently is no way to check file size. If the file is too small to hold an array of doubles of the required length, the function will crash and likely take the R session with it.
Parameters
[in]char**output file name
[in]int*pointer to the number of rows
[in]int*pointer to the number of columns
[out]double*array to be passed to R and converted to a matrix if necessary

◆ GSLmatSave()

void GSLmatSave ( const char **  fileNam,
const double *  vec,
const int *  nRows,
const int *  nCols 
)

Save a double-precision matrix.

The fact that R matrices are column-major, while in C/C++ they are row-major is dealt with internally. The R user does not have to worry about that.

Parameters
[in]char**output file name
[in]double*vectorized matrix to be saved
[in]int*pointer to the number of rows
[in]int*pointer to the number of columns

◆ GSLvecAppend()

void GSLvecAppend ( const char **  fileNam,
const double *  vec,
const int *  len 
)

Appending a double-precision vector to an existing file.

Parameters
[in]char**output file name
[in]double*double-precision array
[in]int*pointer to the array size

◆ GSLvecSave()

void GSLvecSave ( const char **  fileNam,
const double *  vec,
const int *  len 
)

Save a double-precision vector.

Parameters
[in]char**output file name
[in]double*double-precision array
[in]int*pointer to the array size

◆ GSLvecSaveInt()

void GSLvecSaveInt ( const char **  fileNam,
const int *  vec,
const int *  len 
)

Save a vector of integers.

Typically used to save index (factor) vectors to read into RanIndex objects.

Parameters
[in]char**output file name
[in]int*array of integers
[in]int*pointer to the array length