[Rcpp-devel] <no subject>

Dirk Eddelbuettel edd at debian.org
Thu Mar 24 13:33:27 CET 2011


Hi Sean,

On 23 March 2011 at 18:59, Sean Robert McGuffee wrote:
| Hi Dirk and/or List,
| 
| Thanks for the help!
| 
| First  of all, let me apologize for somehow sending this to a Windows related
| discussion--I'm actually on a mac. I'm completely oblivious to how
| email-interfaced discussion groups work.
| 
| Regarding:
| > Can you reduce the problem to something simpler?
| Not easily. Basically, what I'm doing is trying to connect a functional
| command-line-argument based C++ program/library to an R interface. My first
| step was to simply make a C++ function that gets two strings from R to use as
| file names. I got that to work just fine, so my next step was to try to pass
| those to the library--which is where the problem arises. Dissecting out part of
| the library is a mess because I have a tangled web of cross-functionality in
| that library.
| 
| Somewhat related to that:
| Honestly, I'm very new to R and have an extremely difficult time understanding
| most of it's documentation. I think a lot of times the people who write it are

If you're new to R then there is indeed a lot to learn, some of it somewhat
idiosyncratic.  It takes a while but it is worth it.

| close to it and know what they mean, but I tend not to. The skeleton thing
| didn't come with libraries, so I think that is the key to my problem. I have to
| link to my library, and so far I'm attempting that by literally copying all the
| source files into the src directory. I'd much rather just link to the already

Then it is not a library but you would be bundling all source files into the
R package you are trying to create -- which may be simpler in the short run
as you do not to learn how to create a library and link to it. It's not an
uncommon approach either.

| compiled and functional library with small functions but haven't found any way
| to do that. If you could help me with that, I would very much appreciate it. I
| need to link to my library, I assume there might be some need for my headers,
| and also to the headers and libraries referenced by it. If you could give me a
| generic mechanism for doing that, I'd very much appreciate it.

"We" (as in the whole R community) do that via 2900+ working packages on
CRAN. Study those -- pick any one you like and use, and then dissect it.
 
| Regarding:
| > We would need to see what you do in file R/zzz.R and the .onLoad() function
| > (assuming you use a NAMESPACE).  Else we'd need the equivalent .First.lib()
| > function.
| 
| starting by going to my package directory (which worked prior to attempting to
| attach a library)
| 
| cd R_PACKAGES/alignR/
| 
| cat NAMESPACE
| useDynLib(alignR)
| export(colorSpaceToSequenceSpace)
| 
| ls R/
| README                          colorSpaceToSequenceSpace.R
| 
| cat R/colorSpaceToSequenceSpace.R
| colorSpaceToSequenceSpace <- function(colorSpace,sequenceSpace){
| params <- list(colorSpaceFile=colorSpace,sequenceSpaceFile=sequenceSpace)
|         .Call( "colorSpaceToSequenceSpace",params, PACKAGE = "alignR" )
| }
| 
| That's all I have that is unique from the skeleton in that directory. Regarding
| other configuration:
| 
| cd /Library/Frameworks/R.framework/Resources/etc/x86_64
| 
| grep srm Makeconf
| SHLIB_LIBADD = /WHITEHOUSE_LAB/WHITEHOUSE_LAB_PROGRAMS/LIBSRM/LIB/
| libsrm.SeanBenchGcc.so  
| 
| I started off by using a static library
| /WHITEHOUSE_LAB/WHITEHOUSE_LAB_PROGRAMS/LIBSRM/LIB/libsrm.SeanBenchGcc.a
| which I would prefer to use because making the dynamic one was a pain and I'm
| so unfamiliar with that process I don't know if I'm doing it correctly, but
| neither way works so far. I haven't tried including other libraries such as
| libpng14 and shark and some other curve fitting libraries, but it seemed to me
| that if I'm compiling and linking okay and they aren't being called *YET*, that
| should be okay. I would like to know how to link to those in R eventually
| though. Also, I might be wrong about them not mattering if they don't get
| called and wonder if that could be a source of my problem. What I do to use my
| library from the command line is compile interface code with headers from my
| libaries and libaries it references and statically link to it and other
| libraries. I get the feeling that there must be a way to do this in an R
| interface, I'm just not clear as to how.

I would honestly recommend going the "long route" just so you really
understand what is happening:

-- create a test package that just does hello, world 

-- then append an argument to the string printed

-- then vary to do something with any odd external library on your system
   (GSL, or png or shark if you prefer)

and once you have the mechanics sorted out, try your original and larger problem.

Hope this helps, Dirk
 
| I hope this paints a clearer picture of what my problem is.
| 
| Thanks again for any help,
| 
| Sean
| 
| 
| 
| On 3/23/11 7:49 AM, "Dirk Eddelbuettel" <edd at debian.org> wrote:
| 
| >
| > Hi Sean,
| >
| > On 23 March 2011 at 00:20, Sean Robert McGuffee wrote:
| > | Hi,
| > | I?m new to using C++ inside of R. I got a test program to work, so
| > | it?s time for me to attach some function to it. I seem to be having
| > | some issues though. I wonder if anyone out there can help me
| > | understand the results I am getting. I?ve got to a point where it
| > | seems to me that everything is installing but then afterwards it
| >
| > Everything is _compiling_ and _linking_ which is good but...
| >
| > | segmentation faults. In particular the following are the parts where
| > | the problem comes up:
| > | ** testing if installed package can be loaded
| > |  *** caught segfault ***
| > | address 0x20, cause 'memory not mapped'
| >
| > ...when the build process tries to load the package you are building you get
| > a run-time error as is clearly shown by the traceback. Some initalization
| > goes nelly-up, could be your C++ code or your other library
| > (libsrm.SeanBenchGcc ?).
| >
| > Can you reducde the problem to something simpler?
| >
| > | If anyone has any suggestions, please let me know. The full version of
| > | the installation command and results is below:
| >
| > We would need to see what you do in file R/zzz.R and the .onLoad() function
| > (assuming you use a NAMESPACE).  Else we'd need the equivalent .First.lib()
| > function.
| >
| > Dirk
| >
| 
| ----------------------------------------------------------------------
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list