Mercurial > pub > dyncall > bindings
comparison R/rdyncall/demo/stdio.R @ 0:0cfcc391201f
initial from svn dyncall-1745
| author | Daniel Adler |
|---|---|
| date | Thu, 19 Mar 2015 22:26:28 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:0cfcc391201f |
|---|---|
| 1 # Package: rdyncall | |
| 2 # File: demo/stdio.R | |
| 3 # Description: Direct I/O of R raw vectors using C stdio functions | |
| 4 | |
| 5 dynport(stdio) | |
| 6 | |
| 7 # test: fopen returns NULL pointer on error | |
| 8 | |
| 9 nonexisting <- "dummyname" | |
| 10 f <- fopen(nonexisting, "r") | |
| 11 is.nullptr(f) | |
| 12 | |
| 13 # test: R raw object read/write | |
| 14 | |
| 15 tempfile <- "bla" | |
| 16 f <- fopen(tempfile, "wb") | |
| 17 writebuf <- as.raw(0:255) | |
| 18 copy <- writebuf | |
| 19 copy[[1]] <- as.raw(0xFF) | |
| 20 fwrite(writebuf, 1, length(writebuf), f) | |
| 21 fclose(f) | |
| 22 | |
| 23 f <- fopen(tempfile, "rb") | |
| 24 readbuf <- raw(256) | |
| 25 copybuf <- readbuf | |
| 26 fread(readbuf, 1, length(readbuf), f) | |
| 27 copybuf[[1]] <- as.raw(0xFF) | |
| 28 fclose(f) | |
| 29 | |
| 30 identical(readbuf,writebuf) | |
| 31 |
