SCM

SCM Repository

[matrix] Annotation of /pkg/Matrix/man/externalFormats.Rd
ViewVC logotype

Annotation of /pkg/Matrix/man/externalFormats.Rd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3279 - (view) (download) (as text)

1 : bates 825 \name{externalFormats}
2 :     \alias{readHB}
3 :     \alias{readMM}
4 : bates 2049 % \alias{writeHB}
5 : bates 853 \alias{writeMM}
6 : bates 2049 \alias{writeMM,CsparseMatrix-method}
7 : mmaechler 2833 \alias{writeMM,sparseMatrix-method}
8 : bates 825 \title{Read and write external matrix formats}
9 :     \description{
10 : mmaechler 2618 Read matrices stored in the Harwell-Boeing or MatrixMarket formats
11 :     or write \code{\linkS4class{sparseMatrix}} objects to one of these
12 :     formats.
13 : bates 825 }
14 :     \usage{
15 : bates 853 readHB(file)
16 :     readMM(file)
17 : mmaechler 2833 writeMM(obj, file, \dots)
18 : bates 825 }
19 :     \arguments{
20 : bates 853 \item{obj}{a real sparse matrix}
21 : bates 1620 \item{file}{for \code{writeMM} - the name of the file to be written.
22 :     For \code{readHB} and \code{readMM} the name of the file to read, as
23 :     a character scalar. The names of files storing matrices in the
24 :     Harwell-Boeing format usually end in \code{".rua"} or \code{".rsa"}.
25 :     Those storing matrices in the MatrixMarket format usually end in
26 : mmaechler 2311 \code{".mtx"}.
27 : bates 853
28 : bates 1620 Alternatively, \code{readHB} and \code{readMM} accept connection objects.}
29 : bates 853 \item{\dots}{optional additional arguments. Currently none are used in
30 :     any methods.}
31 : bates 825 }
32 :     \value{
33 : bates 853 The \code{readHB} and \code{readMM} functions return an object that
34 : mmaechler 2311 inherits from the \code{"\linkS4class{Matrix}"} class. Methods for the
35 : bates 1620 \code{writeMM} generic functions usually return
36 : mmaechler 2311 \code{\link{NULL}} and, as a side effect, the matrix \code{obj} is
37 :     written to \code{file} in the MatrixMarket format (writeMM).
38 : bates 825 }
39 : bates 1620 \note{
40 :     The Harwell-Boeing format is older and less flexible than the
41 : bates 2049 MatrixMarket format. The function \code{writeHB} was deprecated and
42 : mmaechler 2311 has now been removed. Please use \code{writeMM} instead.
43 : mmaechler 2675
44 :     A very simple way to export small sparse matrices \code{S}, is to use
45 :     \code{summary(S)} which returns a \code{\link{data.frame}} with
46 :     columns \code{i}, \code{j}, and possibly \code{x}, see \code{summary} in
47 :     \code{\link{sparseMatrix-class}}, and an example below.
48 : bates 1620 }
49 : bates 825 \references{
50 : mmaechler 3279 \url{https://math.nist.gov/MatrixMarket}
51 : bates 826
52 : mmaechler 3279 \url{https://www.cise.ufl.edu/research/sparse/matrices}
53 : bates 825 }
54 : bates 826 \examples{
55 : bates 835 str(pores <- readMM(system.file("external/pores_1.mtx",
56 :     package = "Matrix")))
57 :     str(utm <- readHB(system.file("external/utm300.rua",
58 :     package = "Matrix")))
59 :     str(lundA <- readMM(system.file("external/lund_a.mtx",
60 :     package = "Matrix")))
61 :     str(lundA <- readHB(system.file("external/lund_a.rsa",
62 :     package = "Matrix")))
63 : bates 853 \dontrun{
64 : maechler 856 ## NOTE: The following examples take quite some time
65 :     ## ---- even on a fast internet connection:
66 : mmaechler 2327 if(FALSE) # the URL has been corrected, but we need an un-tar step!
67 : bates 857 str(sm <-
68 : mmaechler 2327 readHB(gzcon(url("http://www.cise.ufl.edu/research/sparse/RB/Boeing/msc00726.tar.gz"))))
69 :    
70 : bates 853 str(jgl009 <-
71 :     readMM(gzcon(url("ftp://math.nist.gov/pub/MatrixMarket2/Harwell-Boeing/counterx/jgl009.mtx.gz"))))
72 : bates 826 }
73 : maechler 1228 data(KNex)
74 : mmaechler 3279 ## Store as MatrixMarket (".mtx") file, here inside temporary dir./folder:
75 :     (MMfile <- file.path(tempdir(), "mmMM.mtx"))
76 :     writeMM(KNex$mm, file=MMfile)
77 :     file.info(MMfile)[,c("size", "ctime")] # (some confirmation of the file's)
78 : mmaechler 2675
79 :     ## very simple export - in triplet format - to text file:
80 : mmaechler 2677 data(CAex)
81 : mmaechler 2675 s.CA <- summary(CAex)
82 : mmaechler 3143 s.CA # shows (i, j, x) [columns of a data frame]
83 : mmaechler 2675 message("writing to ", outf <- tempfile())
84 :     write.table(s.CA, file = outf, row.names=FALSE)
85 : mmaechler 2677 ## and read it back -- showing off sparseMatrix():
86 : mmaechler 3143 str(dd <- read.table(outf, header=TRUE))
87 :     ## has columns (i, j, x) -> we can use via do.call() as arguments to sparseMatrix():
88 : mmaechler 2677 mm <- do.call(sparseMatrix, dd)
89 : mmaechler 2960 stopifnot(all.equal(mm, CAex, tolerance=1e-15))
90 : bates 853 }
91 : bates 825 \keyword{IO}
92 : bates 853 \keyword{array}
93 : bates 825 \keyword{algebra}

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge