[R] Rmpfr question

Martin Maechler maechler at lynne.ethz.ch
Tue Sep 24 11:55:29 CEST 2013


>>>>> "M" == Michel  <michelgomez at free.fr>
>>>>>     on Fri, 20 Sep 2013 17:56:58 +0200 writes:

    > Hello everyone, R beginner, I am confronted with the need
    > to use Rmpf.
why ?

    > In my first scripts I made use of
    > X=read.table(file.choose(), header=FALSE, sep=",",dec=".")  
    > X=as.matrix(X)

well, the above is not at all reproducible {we don't see *nor*
have the file you chose with file.choose() !}
so that's maybe why nobody helped ...

Does the file have numbers in high precision, i.e. more than
about 15-16 digits?
I'm assuming "no" for the moment.
If "yes" was the answer, then you really need to read the data
quite differently.
In that case please, show us the first few lines  of your file.


    > to load into a matrix data from file before matrix use.

    > How can I do to load the same data in a "mpfrMatrix".

As you already have the regular numeric matrix X,
you can either use

    M <- as(X, "mpfr") # uses default precision of 128 bits
or
    M <- mpfr(X, precBits = 200)

where you choose the precision of the numbers via 'precBits'


    > Is it possible to use with "mpfrMatrix" the same as
    > operations

    > M1 %*% M2

yes, matrix multiplications all work ... though a bit slowly.
matrix factorizations (eigen, svd, qr, solve,..) all do not
(yet; patches are welcome; I'm currently working at an LU decomposition).

    >  scale(M1,TRUE,FALSE)

not directly, in the current version of Rmpfr.
But you can use the following trick:

    scale.mpfrMatrix <- scale.default
    environment(scale.mpfrMatrix) <- asNamespace("Rmpfr")

and then it will work.


    > Sorry but I'm a newbe

let's hope, not for too long ;-) ;-)

    > Thanks in advance
    > Michel

You're welcome,
Martin Maechler, ETH Zurich

(maintainer of the 'Rmpfr' package.
 Yes, I know you also sent the question to me privately, 
 but only several days *after* asking on R-help; it would have
 been nice, if you had mentioned that you also asked here and
 nobody helped you.  ...)



More information about the R-help mailing list