write_matrix | R Documentation |
The inverse function of read_matrix()
, this writes what is intended to be a numeric matrix to a tab-delimited file without row or column names present.
It uses readr::write_tsv()
to do it efficiently.
Intended for outputs such as those of admixture inference approaches.
write_matrix(file, x, ext = "txt", verbose = TRUE, append = FALSE)
file |
Output file (whatever is accepted by |
x |
The matrix to write.
Unlike |
ext |
The desired file extension.
If |
verbose |
If |
append |
If |
The output x
, coerced into data.frame, invisibly (what readr::write_tsv()
returns).
read_matrix()
, the inverse function.
# to write an existing matrix `x` into file "data.txt", run like this: # write_matrix( "data", x ) # this also works # write_matrix( "data.txt", x ) # The following example is more detailed but also more awkward # because (only for these examples) the package must create the file in a *temporary* location # create a dummy matrix with the right columns x <- rbind( 1:3, (0:2)/10, -1:1 ) # a dummy file file_out <- tempfile('delete-me-example', fileext = '.txt') # will also work without extension # write the matrix without header write_matrix( file_out, x ) # delete output when done file.remove( file_out )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.