[Rd] Problem using ofstream in C++ class in package for MacOS X

cstrato cstrato at aon.at
Sun Feb 4 20:17:51 CET 2007


Dear all,

I am currently learning how to create R packages using C++ classes.
For this purpose I have written a small package MyClass (which I try
to attach since I do not have access to a website).

MyClass has methods WriteFileC() and WriteFileCpp() which implement
C-style and C++-style writing of a table to a file using FILE or
ofstream respectively, and the corresponding R-functions writeFileC.R
and writeFileCpp.R.

While I can compile and execute my package w/o problems on Fedora Core 4,
I can only execute writeFileC.R on my Intel-MacBook Pro, but not 
writeFileCpp.R.
Executing my functions I get the following output:

 > library(MyClass)

Welcome to MyClass
 > writeFileC("myout_fileC.txt")
[1] "outfile =  myout_fileC.txt"
Writing file myout_fileC.txt using C style.
---MyClassA::MyClassA()---------
---MyClassA::WriteFileC---------
<20> records exported.
---MyClassA::~MyClassA()---------
[1] "writeFileC finished"
NULL
 > writeFileCpp("myout_fileCpp.txt")
[1] "outfile =  myout_fileCpp.txt"
Writing file myout_fileCpp.txt using C++ style.
---MyClassA::MyClassA()---------
---MyClassA::WriteFileCpp---------

 *** caught bus error ***
address 0x6, cause 'non-existent physical address'

Traceback:
 1: .C("WriteFileCpp", as.character(outfile), PACKAGE = "MyClass")
 2: writeFileCpp("myout_fileCpp.txt")


While I understand, that C++ iostreams are best avoided, since there is
no guarantee that the output will appear in the R console (as mentioned
on page 62 of R-exts.pdf), I do not understand why I cannot use ofstream,
which is isolated in a C++ method only.

Is there a way how to use ofstream on MacOS X or is this a limit of the
current Mac implementation?

Thank you in advance.
Best regards
Christian
_._._._._._._._._._._._._._._._
C.h.i.s.t.i.a.n S.t.r.a.t.o.w.a
V.i.e.n.n.a       A.u.s.t.r.i.a
_._._._._._._._._._._._._._._._

-------------- next part --------------
A non-text attachment was scrubbed...
Name: MyClass_0.1.2.tar.gz
Type: application/x-gzip
Size: 9198 bytes
Desc: not available
Url : https://stat.ethz.ch/pipermail/r-devel/attachments/20070204/2e7fb79c/attachment.gz 


More information about the R-devel mailing list