R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("R.matlab-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('R.matlab') Loading required package: R.oo R.oo v1.0.3 (2005-05-02) successfully loaded. See ?R.oo for help. R.matlab v1.0.2 (2005-05-03) successfully loaded. See ?R.matlab for help. > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "Java" > > ### * Java > > flush(stderr()); flush(stdout()) > > ### Name: Java > ### Title: Static class for Java related methods > ### Aliases: Java > ### Keywords: classes > > ### ** Examples > > pathname <- tempfile() > > # Open the temporary file for writing > out <- file(pathname, open="wb") > b <- -128:127 > Java$writeByte(out, b) > s <- -32768:32767 > Java$writeShort(out, s) > i <- c(-2147483648, -2147483647, -1, 0, +1, 2147483646, 2147483647); > Java$writeInt(out, i) > str <- "This R string was written (using the UTF-8 format) using\nthe static methods of the Java class in the R.io package." > Java$writeUTF(out, str) > close(out) > > # Open the temporary file for reading > inn <- file(pathname, open="rb") > > bfr <- Java$readByte(inn, n=length(b)) > cat("Read ", length(bfr), " bytes.\n", sep="") Read 256 bytes. > if (!identical(bfr, b)) + throw("Failed to read the same data that was written.") > > bfr <- Java$readShort(inn, n=length(s)) > cat("Read ", length(bfr), " shorts.\n", sep="") Read 65536 shorts. > if (!identical(bfr, s)) + throw("Failed to read the same data that was written.") > > bfr <- Java$readInt(inn, n=length(i)) > cat("Read ", length(bfr), " ints.\n", sep="") Read 7 ints. > if (!identical(bfr, i)) + throw("Failed to read the same data that was written.") > > bfr <- Java$readUTF(inn) > cat("Read ", nchar(bfr), " UTF characters:\n", "'", bfr, "'\n", sep="") Read 114 UTF characters: 'This R string was written (using the UTF-8 format) using the static methods of the Java class in the R.io package.' > > close(inn) > > file.remove(pathname) [1] TRUE > > > > cleanEx(); ..nameEx <- "Matlab" > > ### * Matlab > > flush(stderr()); flush(stdout()) > > ### Name: Matlab > ### Title: Matlab client for remote or local Matlab access > ### Aliases: Matlab > ### Keywords: classes > > ### ** Examples > ## Not run: > ##D # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > ##D # This example will try to connect to the Matlab server running on the > ##D # same machine. > ##D # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > ##D # Create a Matlab client > ##D matlab <- Matlab(host="localhost") > ##D > ##D # Connect to the Matlab server > ##D if (!open(matlab)) > ##D throw("Matlab server is not running: waited 30 seconds.") > ##D > ##D # Run Matlab expressions on the Matlab server > ##D res <- evaluate(matlab, "A=1+2;", "B=ones(2,20);") > ##D > ##D # Get Matlab variables > ##D data <- getVariable(matlab, c("A", "B")) > ##D cat("Recieved variables:\n") > ##D str(data) > ##D > ##D # Set variables in Matlab > ##D ABCD <- matrix(rnorm(10000), ncol=100) > ##D str(ABCD) > ##D setVariable(matlab, ABCD=ABCD) > ##D > ##D # Retrieve what we just set > ##D data <- getVariable(matlab, "ABCD") > ##D cat("Recieved variables:\n") > ##D str(data) > ##D > ##D # Create a function (M-file) on the Matlab server > ##D setFunction(matlab, " \ > ##D function [win,aver]=dice(B) \ > ##D %Play the dice game B times \ > ##D gains=[-1,2,-3,4,-5,6]; \ > ##D plays=unidrnd(6,B,1); \ > ##D win=sum(gains(plays)); \ > ##D aver=win/B; \ > ##D "); > ##D > ##D evaluate(matlab, "[w,a]=dice(1000);") > ##D res <- getVariable(matlab, c("w", "a")) > ##D print(res) > ##D > ##D # When done, close the Matlab client, which will also shutdown > ##D # the Matlab server and the connection to it. > ##D close(matlab) > ##D > ## End(Not run) > > > cleanEx(); ..nameEx <- "readMat" > > ### * readMat > > flush(stderr()); flush(stdout()) > > ### Name: readMat > ### Title: Reads a MAT file structure from a connection or a file > ### Aliases: readMat.default readMat > ### Keywords: file IO > > ### ** Examples > > path <- system.file("mat-files", package="R.matlab") > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > # Reading all example files > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > for (version in 4:5) { + cat("Loading all MAT v", version, " example files in ", + path, "...\n", sep="") + + pattern <- sprintf("-v%d.mat$", version) + filenames <- list.files(pattern=pattern, path=path, full.names=TRUE) + + for (filename in filenames) { + cat("Reading MAT file: ", basename(filename), "\n", sep="") + mat <- readMat(filename) + if (interactive()) { + cat("Press ENTER to view data:") + readline() + } + print(mat) + } + } Loading all MAT v4 example files in /CRANPkg/check/R.matlab.Rcheck/R.matlab/mat-files... Reading MAT file: Matrix-BigEndian-v4.mat $x [,1] [1,] 0.05322716 [2,] 0.74638659 [3,] 0.26134080 [4,] 0.16421010 [5,] 0.63433397 attr(,"header") attr(,"header")$version [1] "4" attr(,"header")$endian [1] "big" Reading MAT file: Matrix-v4.mat $x [,1] [1,] -1.49775124 [2,] -1.10704029 [3,] 1.18735480 [4,] 0.21151473 [5,] -1.21211421 [6,] -0.03170872 [7,] -0.39826268 [8,] -1.51964319 [9,] 0.48633114 [10,] 0.23586598 attr(,"header") attr(,"header")$version [1] "4" attr(,"header")$endian [1] "little" Reading MAT file: SparseMatrix-v4.mat $S [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [1,] 1 0 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 1 0 0 0 0 0 0 0 0 0 0 0 [3,] 0 0 1 0 0 0 0 0 0 0 0 0 0 [4,] 0 0 0 1 0 0 0 0 0 0 0 0 0 [5,] 0 0 0 0 1 0 0 0 0 0 0 0 0 [6,] 0 0 0 0 0 1 0 0 0 0 0 0 0 [7,] 0 0 0 0 0 0 1 0 0 0 0 0 0 [8,] 0 0 0 0 0 0 0 1 0 0 0 0 0 [9,] 0 0 0 0 0 0 0 0 1 0 0 0 0 [10,] 0 0 0 0 0 0 0 0 0 1 0 0 0 [11,] 0 0 0 0 0 0 0 0 0 0 1 0 0 [12,] 0 0 0 0 0 0 0 0 0 0 0 1 0 [13,] 0 0 0 0 0 0 0 0 0 0 0 0 1 [14,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [15,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [16,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [17,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [18,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [19,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [20,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [,14] [,15] [,16] [,17] [,18] [,19] [,20] [1,] 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 [3,] 0 0 0 0 0 0 0 [4,] 0 0 0 0 0 0 0 [5,] 0 0 0 0 0 0 0 [6,] 0 0 0 0 0 0 0 [7,] 0 0 0 0 0 0 0 [8,] 0 0 0 0 0 0 0 [9,] 0 0 0 0 0 0 0 [10,] 0 0 0 0 0 0 0 [11,] 0 0 0 0 0 0 0 [12,] 0 0 0 0 0 0 0 [13,] 0 0 0 0 0 0 0 [14,] 1 0 0 0 0 0 0 [15,] 0 1 0 0 0 0 0 [16,] 0 0 1 0 0 0 0 [17,] 0 0 0 1 0 0 0 [18,] 0 0 0 0 1 0 0 [19,] 0 0 0 0 0 1 0 [20,] 0 0 0 0 0 0 0 attr(,"header") attr(,"header")$version [1] "4" attr(,"header")$endian [1] "big" Reading MAT file: SparseMatrix3-v4.mat $sparseM [,1] [,2] [,3] [,4] [,5] [1,] 0.95012929 0.8214072 0.9354697 0.13889088 0.4450964 [2,] 0.23113851 0.4447034 0.9169044 0.20276522 0.9318146 [3,] 0.60684258 0.6154323 0.4102702 0.19872174 0.4659943 [4,] 0.48598247 0.7919370 0.8936495 0.60379248 0.4186495 [5,] 0.89129897 0.9218130 0.0578913 0.27218792 0.8462214 [6,] 0.76209683 0.7382072 0.3528681 0.19881427 0.5251525 [7,] 0.45646767 0.1762661 0.8131665 0.01527393 0.2026474 [8,] 0.01850364 0.4057062 0.0098613 0.74678568 0.6721375 attr(,"header") attr(,"header")$version [1] "4" attr(,"header")$endian [1] "big" Loading all MAT v5 example files in /CRANPkg/check/R.matlab.Rcheck/R.matlab/mat-files... Reading MAT file: Matrix-LittleEndian-v5.mat $x [,1] [1,] 0.05322716 [2,] 0.74638659 [3,] 0.26134080 [4,] 0.16421010 [5,] 0.63433397 attr(,"header") attr(,"header")$description [1] "MATLAB 5.0 MAT-file, Platform: SOL2, Created on: Tue Feb 10 14:37:03 2004 " attr(,"header")$version [1] "5" attr(,"header")$endian [1] "big" Reading MAT file: Matrix-v5.mat $X , , 1 [,1] x Numeric,6 y List,2 z Numeric,196 attr(,"header") attr(,"header")$description [1] "MATLAB 5.0 MAT-file, Platform: PCWIN, Created on: Tue Aug 27 01:25:36 2002 " attr(,"header")$version [1] "5" attr(,"header")$endian [1] "little" Reading MAT file: SparseMatrix-v5.mat $S [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [1,] 1 0 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 1 0 0 0 0 0 0 0 0 0 0 0 [3,] 0 0 1 0 0 0 0 0 0 0 0 0 0 [4,] 0 0 0 1 0 0 0 0 0 0 0 0 0 [5,] 0 0 0 0 1 0 0 0 0 0 0 0 0 [6,] 0 0 0 0 0 1 0 0 0 0 0 0 0 [7,] 0 0 0 0 0 0 1 0 0 0 0 0 0 [8,] 0 0 0 0 0 0 0 1 0 0 0 0 0 [9,] 0 0 0 0 0 0 0 0 1 0 0 0 0 [10,] 0 0 0 0 0 0 0 0 0 1 0 0 0 [11,] 0 0 0 0 0 0 0 0 0 0 1 0 0 [12,] 0 0 0 0 0 0 0 0 0 0 0 1 0 [13,] 0 0 0 0 0 0 0 0 0 0 0 0 1 [14,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [15,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [16,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [17,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [18,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [19,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [20,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [,14] [,15] [,16] [,17] [,18] [,19] [,20] [1,] 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 [3,] 0 0 0 0 0 0 0 [4,] 0 0 0 0 0 0 0 [5,] 0 0 0 0 0 0 0 [6,] 0 0 0 0 0 0 0 [7,] 0 0 0 0 0 0 0 [8,] 0 0 0 0 0 0 0 [9,] 0 0 0 0 0 0 0 [10,] 0 0 0 0 0 0 0 [11,] 0 0 0 0 0 0 0 [12,] 0 0 0 0 0 0 0 [13,] 0 0 0 0 0 0 0 [14,] 1 0 0 0 0 0 0 [15,] 0 1 0 0 0 0 0 [16,] 0 0 1 0 0 0 0 [17,] 0 0 0 1 0 0 0 [18,] 0 0 0 0 1 0 0 [19,] 0 0 0 0 0 1 0 [20,] 0 0 0 0 0 0 0 attr(,"name") [1] "S" attr(,"header") attr(,"header")$description [1] "MATLAB 5.0 MAT-file, Platform: SOL2, Created on: Tue Feb 10 16:40:52 2004 " attr(,"header")$version [1] "5" attr(,"header")$endian [1] "big" Reading MAT file: SparseMatrix2-v5.mat $sparseM [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [1,] 1 0 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 1 3 4 5 0 0 0 0 0 0 0 0 [3,] 0 0 1 0 0 0 0 0 0 0 0 0 0 [4,] 0 0 0 1 0 0 0 0 0 0 0 0 0 [5,] 0 0 0 0 1 0 0 0 0 0 0 0 0 [6,] 0 0 0 0 0 1 0 0 0 0 0 0 0 [7,] 0 0 0 0 0 0 1 0 0 0 0 0 0 [8,] 0 0 0 0 0 0 0 1 0 0 0 0 0 [9,] 0 0 0 0 0 0 0 0 1 0 0 0 0 [10,] 0 0 0 0 0 0 0 0 0 1 0 0 0 [11,] 0 0 0 0 0 0 0 0 0 0 1 0 0 [12,] 0 0 0 0 0 0 0 0 0 0 0 1 0 [13,] 0 0 0 0 0 0 0 0 0 0 0 0 1 [14,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [15,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [16,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [17,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [18,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [19,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [20,] 0 0 0 0 0 0 0 0 0 0 0 0 0 [,14] [,15] [,16] [,17] [,18] [1,] 0 0 0 0 0 [2,] 0 0 0 0 0 [3,] 0 0 0 0 0 [4,] 0 0 0 0 0 [5,] 0 0 0 0 0 [6,] 0 0 0 0 0 [7,] 0 0 0 0 0 [8,] 0 0 0 0 0 [9,] 0 0 0 0 0 [10,] 0 0 0 0 0 [11,] 0 0 0 0 0 [12,] 0 0 0 0 0 [13,] 0 0 0 0 0 [14,] 1 0 0 0 0 [15,] 0 1 0 0 0 [16,] 0 0 1 0 0 [17,] 0 0 0 1 0 [18,] 0 0 0 0 1 [19,] 0 0 0 0 0 [20,] 0 0 0 0 0 attr(,"name") [1] "sparseM" attr(,"header") attr(,"header")$description [1] "MATLAB 5.0 MAT-file, Platform: SOL2, Created on: Tue Feb 10 19:00:09 2004 " attr(,"header")$version [1] "5" attr(,"header")$endian [1] "big" Reading MAT file: SparseMatrix3-v5.mat $sparseM [,1] [,2] [,3] [,4] [,5] [1,] 0.95012929 0.8214072 0.9354697 0.13889088 0.4450964 [2,] 0.23113851 0.4447034 0.9169044 0.20276522 0.9318146 [3,] 0.60684258 0.6154323 0.4102702 0.19872174 0.4659943 [4,] 0.48598247 0.7919370 0.8936495 0.60379248 0.4186495 [5,] 0.89129897 0.9218130 0.0578913 0.27218792 0.8462214 [6,] 0.76209683 0.7382072 0.3528681 0.19881427 0.5251525 [7,] 0.45646767 0.1762661 0.8131665 0.01527393 0.2026474 [8,] 0.01850364 0.4057062 0.0098613 0.74678568 0.6721375 attr(,"name") [1] "sparseM" attr(,"header") attr(,"header")$description [1] "MATLAB 5.0 MAT-file, Platform: SOL2, Created on: Tue Feb 10 19:37:28 2004 " attr(,"header")$version [1] "5" attr(,"header")$endian [1] "big" Reading MAT file: SparseMatrixPage20-v5.mat $S [,1] [,2] [,3] [1,] 1.5 0.0 0.0 [2,] 0.0 2.5 0.0 [3,] 0.0 0.0 3.5 attr(,"name") [1] "S" attr(,"header") attr(,"header")$description [1] "MATLAB 5.0 MAT-file, Platform: SOL2, Created on: Tue Feb 10 18:12:51 2004 " attr(,"header")$version [1] "5" attr(,"header")$endian [1] "big" Reading MAT file: struct-v5.mat $X , , 1 [,1] x Numeric,6 y List,2 z Numeric,196 attr(,"header") attr(,"header")$description [1] "MATLAB 5.0 MAT-file, Platform: PCWIN, Created on: Tue Aug 27 01:25:36 2002 " attr(,"header")$version [1] "5" attr(,"header")$endian [1] "little" > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > # Verify that sparse matrices are read the same way in MAT v4 and MAT v5 > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > mat4 <- readMat(file.path(path, "SparseMatrix3-v4.mat")) > mat5 <- readMat(file.path(path, "SparseMatrix3-v5.mat")) > diff <- sum(abs(mat4$sparseM - mat5$sparseM)) > if (diff > .Machine$double.eps) + stop("Failed to read identical MAT v4 and MAT v5 sparse matrices.") > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > # Assert that signed and unsigned integer sare read correctly > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > bs <- readMat(file.path(path, "unsignedByte.mat")) > if (!identical(as.vector(bs$A), as.double(126:255))) + stop("Error reading unsigned bytes saved by Matlab.") > > is <- readMat(file.path(path, "unsignedInt.mat")) > if (!identical(as.vector(is$B), as.double(127:256))) + stop("Error reading unsigned ints saved by Matlab.") > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > # Example of a Matlab struct > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > # File was created by > # s = struct('type',{'big','little'}, 'color','red', 'x',{3,4}) > # 1x2 struct array with fields: > # type > # color > # x > # save structLooped.mat s -v6 > mat <- readMat(file.path(path, "structLooped.mat")) > > # Extract the structure > s <- mat$s > > # Field names are always in the first dimension > fields <- dimnames(s)[[1]] > cat("Field names: ", paste(fields, collapse=", "), "\n", sep=""); Field names: type, color, x > > print(s) , , 1 [,1] type "big" color "red" x 3 , , 2 [,1] type "little" color "red" x 4 > > # Get field 'type' > print(s["type",,]) [[1]] [,1] [1,] "big" [[2]] [,1] [1,] "little" > > # Get substructure s(:,2) > print(s[,,2]) $type [,1] [1,] "little" $color [,1] [1,] "red" $x [,1] [1,] 4 > > > > cleanEx(); ..nameEx <- "setFunction.Matlab" > > ### * setFunction.Matlab > > flush(stderr()); flush(stdout()) > > ### Name: setFunction.Matlab > ### Title: Defines a Matlab function > ### Aliases: setFunction.Matlab Matlab.setFunction setFunction.Matlab > ### setFunction,Matlab-method > ### Keywords: methods internal > > ### ** Examples > ## Not run: code <- c( > ##D "function [win,aver]=dice(B)", > ##D "%Play the dice game B times", > ##D "gains=[-1,2,-3,4,-5,6];", > ##D "plays=unidrnd(6,B,1);", > ##D "win=sum(gains(plays));", > ##D "aver=win;" > ##D ) > ##D > ##D setFunction(matlab, code) > ##D evaluate(matlab, "[w,a]=dice(1000);") > ##D res <- getVariable(matlab, c("w", "a")) > ##D print(res) > ##D > ## End(Not run) > > > cleanEx(); ..nameEx <- "writeMat" > > ### * writeMat > > flush(stderr()); flush(stdout()) > > ### Name: writeMat > ### Title: Writes a MAT file structure > ### Aliases: writeMat.default writeMat > ### Keywords: file IO > > ### ** Examples > A <- matrix(1:27, ncol=3) > B <- as.matrix(1:10) > > filename <- paste(tempfile(), ".mat", sep="") > > writeMat(filename, A=A, B=B) > data <- readMat(filename) > print(data) $A [,1] [,2] [,3] [1,] 1 10 19 [2,] 2 11 20 [3,] 3 12 21 [4,] 4 13 22 [5,] 5 14 23 [6,] 6 15 24 [7,] 7 16 25 [8,] 8 17 26 [9,] 9 18 27 $B [,1] [1,] 1 [2,] 2 [3,] 3 [4,] 4 [5,] 5 [6,] 6 [7,] 7 [8,] 8 [9,] 9 [10,] 10 attr(,"header") attr(,"header")$description [1] "MATLAB 5.0 MAT-file, Platform: unix, Software: R v2.1.1, Created on: Wed Jul 13 10:52:57 2005 " attr(,"header")$version [1] "5" attr(,"header")$endian [1] "little" > > unlink(filename) > > ## Not run: > ##D # When writing to a stream connection the receiver needs to know in > ##D # beforehand how many bytes are available. This can be done by using > ##D # the 'onWrite' argument. > ##D onWrite <- function(x) > ##D writeBin(x$length, con=x$con, size=4, endian="little"); > ##D writeMat(con, A=A, B=B, onWrite=onWrite) > ## End(Not run) > > > > ### *