Saving a matrix in binary format

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Saving a matrix in binary format

Indrajit Chatterjee
Hi - is it possible to save and load a matrix in binary form using R?

 

For example save.matrix() - and load.matrix() , but where the saves and
loads are in binary format for speed and compactness.


        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
Reply | Threaded
Open this post in threaded view
|

Re: Saving a matrix in binary format

Steven D. Moffitt
Dear Mr. Chatterjee,

I'm not aware of a function that does this generically, and I doubt there exists one in the standard relase of R for the following reason - different processors have different numerical formats that would require a specialized format for general purpose floating-point storage.  For example, Intel processors have a little endian architecture whereas Sparcs have a big endian architecture.  Different processors represent doubles differently, so that a read of a bits forming a double from one processor won't be correct for another.  at the present time, processors are transitioning from 32-bit to 64-bit, making it necessary to distinguish 64-bit doubles from 80-bit doubles from 128-bit 'long doubles.'  

In short, while it is possible to write a C/C++ program that would accomplish what you want, it wouldn't be portable.  Even an upgrade from an Intel x86 processor to an Itanium processor could give problems!

Steve Moffitt

Director of Research
WH Trading, LLC



---------- Original Message ----------------------------------
From: "Indrajit Chatterjee" <[hidden email]>
Date:  Wed, 5 Apr 2006 11:16:19 -0700

>Hi - is it possible to save and load a matrix in binary form using R?
>
>
>
>For example save.matrix() - and load.matrix() , but where the saves and
>loads are in binary format for speed and compactness.
>
>
> [[alternative HTML version deleted]]
>
>_______________________________________________
>[hidden email] mailing list
>https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
Reply | Threaded
Open this post in threaded view
|

Re: Saving a matrix in binary format

Dirk Eddelbuettel
In reply to this post by Indrajit Chatterjee

On 5 April 2006 at 11:16, Indrajit Chatterjee wrote:
| Hi - is it possible to save and load a matrix in binary form using R?
|
|  
|
| For example save.matrix() - and load.matrix() , but where the saves and
| loads are in binary format for speed and compactness.

See  help(save)   -- it is even better than what you ask for as it works for
every R data type, allows for compression and is portable across portable
thanks to the underlying xdr binary representation.  It is the same format R
uses when it saves an interactive session.

Hope this helps, Dirk

--
Hell, there are no rules here - we're trying to accomplish something.
                                                  -- Thomas A. Edison

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
Reply | Threaded
Open this post in threaded view
|

Re: Saving a matrix in binary format

Whit Armstrong
In reply to this post by Indrajit Chatterjee
Have a look at .saveRDS.  I use it extensively.


     .saveRDS(object, file = "", ascii = FALSE, version = NULL,
              compress = FALSE, refhook = NULL)
     .readRDS(file, refhook = NULL)



-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Steven D.
Moffitt
Sent: Wednesday, April 05, 2006 4:01 PM
To: [hidden email]; Indrajit Chatterjee
Subject: Re: [R-sig-finance] Saving a matrix in binary format

Dear Mr. Chatterjee,

I'm not aware of a function that does this generically, and I doubt
there exists one in the standard relase of R for the following reason -
different processors have different numerical formats that would require
a specialized format for general purpose floating-point storage.  For
example, Intel processors have a little endian architecture whereas
Sparcs have a big endian architecture.  Different processors represent
doubles differently, so that a read of a bits forming a double from one
processor won't be correct for another.  at the present time, processors
are transitioning from 32-bit to 64-bit, making it necessary to
distinguish 64-bit doubles from 80-bit doubles from 128-bit 'long
doubles.'  

In short, while it is possible to write a C/C++ program that would
accomplish what you want, it wouldn't be portable.  Even an upgrade from
an Intel x86 processor to an Itanium processor could give problems!

Steve Moffitt

Director of Research
WH Trading, LLC



---------- Original Message ----------------------------------
From: "Indrajit Chatterjee" <[hidden email]>
Date:  Wed, 5 Apr 2006 11:16:19 -0700

>Hi - is it possible to save and load a matrix in binary form using R?
>
>
>
>For example save.matrix() - and load.matrix() , but where the saves and

>loads are in binary format for speed and compactness.
>
>
> [[alternative HTML version deleted]]
>
>_______________________________________________
>[hidden email] mailing list
>https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance