[R] Reshaping an array - how does it work in R

Rodrigo Botafogo rodrigo at rodrigobotafogo.com
Mon Mar 21 15:26:19 CET 2016


Roy,

I have implemented a Ruby Gem (SciCom) with exactly your use case in mind.
SciCom is based on Renjin, an R interpreter for the JVM.  So, this reply is
about R, but not about GnuR.  If this is not proper behavior, please let me
know.  I´ve looked at the posting guidelines and it seems to be ok.

SciCom interfaces with another Ruby Gem: MDArray.  MDArray is a
multidimensional array class that is based on NetCDF-Java.  It can read
netcdf files and store them in a multidimensional array.  MDArray can be
reshaped and also sliced and diced as you can do with NetCDF.  Reshaping an
MDArray does not require any copying, it is just index manipulations.

An MDArray can then be "send" to SciCom.  This is not really sending, since
there is no data copying either and the array is just wrapped in such a way
that it can be used in Renjin.  In Renjin you could use normal R functions
to process this data and do your analysis.

The data in SciCom can thus be viewed either as an R array, to which R
sematics apply and reshaping will copy the data, or as an MDArray, and
reshaping and slicing/dicing does not do any copying.  It is up to the
developer to be careful how to see the data and operate on it.

There are however two showstoppers: i) Renjin does not load all CRAN
packages yet.  So, there is a good chance that if you need a package for
your PCA analysis, that this will not be loaded; ii) SciCom/Renjin do not
support any graphics such as plot/ggplot.

References:

Renjin: http://www.renjin.org/
NetCDF-Java:
http://www.unidata.ucar.edu/software/thredds/current/netcdf-java/
MDArray: https://github.com/rbotafogo/mdarray/wiki
SciCom:
    https://github.com/rbotafogo/scicom

https://github.com/rbotafogo/scicom/wiki/A-(not-so)-Short-Introduction-to-SciCom

-- 
Rodrigo Botafogo

	[[alternative HTML version deleted]]



More information about the R-help mailing list