annotate R/rdyncall/demo/stdio.R @ 3:f5d4d5c2f750

- gemspec fix
author cslag
date Thu, 31 Dec 2015 20:24:53 +0100
parents 0cfcc391201f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 # Package: rdyncall
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2 # File: demo/stdio.R
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 # Description: Direct I/O of R raw vectors using C stdio functions
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 dynport(stdio)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 # test: fopen returns NULL pointer on error
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
9 nonexisting <- "dummyname"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 f <- fopen(nonexisting, "r")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11 is.nullptr(f)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 # test: R raw object read/write
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15 tempfile <- "bla"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 f <- fopen(tempfile, "wb")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 writebuf <- as.raw(0:255)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 copy <- writebuf
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 copy[[1]] <- as.raw(0xFF)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 fwrite(writebuf, 1, length(writebuf), f)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 fclose(f)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23 f <- fopen(tempfile, "rb")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 readbuf <- raw(256)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25 copybuf <- readbuf
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26 fread(readbuf, 1, length(readbuf), f)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27 copybuf[[1]] <- as.raw(0xFF)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28 fclose(f)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 identical(readbuf,writebuf)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31