Collapse list of mpfr objects into single mpfr vector

545 views Asked by At

I must be missing something obvious:

library(Rmpfr)

list.mpfr <- list(mpfr(10, 128), mpfr(20, 128))  # I'd like to turn this into mpfr(c(10, 20), 128)
test <- c(list.mpfr, recursive=TRUE)  # Doesn't work -- should it?
identical(test, list.mpfr)  # False -- test is a list of mpfr1 and no longer a list of mpfr

## I'd expect c.mpfr(..., recursive=TRUE) to do the equivalent of c(list(1:5, 8:10), recursive=TRUE)
getAnywhere(c.mpfr)

I have a function that returns an mpfr of length one. I use mapply(..., simplify=FALSE) to build up something similar to list.mpfr in the example above. I'd like to combine the length-1 mpfr objects into a single mpfr object (so that I can call which.max, for example).

1

There are 1 answers

0
Adrian On BEST ANSWER

Found a solution:

library(Rmpfr)
list.mpfr <- list(mpfr(10, 128), mpfr(20, 128))
desired <- new("mpfr", unlist(list.mpfr))
identical(desired, mpfr(c(10, 20), 128))  # True