Many thanks: R CMD SHLIB is proably what I was looking for....do you know
where the most extensive documentation for that is located? I looked at
the man page for R and R CMD SHLIP --help, but there wasn't much detail on
how it works. Does it (or can it be configured to) run a makefile? (I have
been compiling the C using a makefile written by someone else: the larger
picture is that we're trying to write R wrappers for a bunch of C
programs---my colleague is modifying the C---so eventually they'll be
put in a package's /src directory, but for now I am just trying to test by
making sure they can be called from R before putting them together in a
package. So far I've just been using system(), which works fine on my
machine, but all the packages I've looked at use .C()/.Call() in
preference to system(), so I assume I should be learning how to use
.C()/.Call()....

Thanks,
Walton

On Sat, 29 Oct 2005, Duncan Temple Lang wrote:

> Hi Walton.
>
> .C/.Call are interfaces to _compiled_ C routines in a dynamically
> loaded library (DLL or DSO - shared object). A progra
> A program is often created from compiling C code into an executable.
> We can call the executable via system, but we cannot access its routines
> via .C/.Call.
>
> So, if you have C code, use R CMD SHLIB to compile it into a loadable
> libray and use dyn.load() to load it. Putting the code in the src/
> directory of a package makes the need to do this less explicit.
>
> But if you want to use system(), again it can be done "portably" in a
> package.
> Arrange that the package creates and puts the executable in
> the package's installed area. Arrange that the program is
> put in, say, inst/bin within the package and then it will be installed
> into the bin/ directory of the package. Then you can access it with
>
> system.file("bin", "myProg", package = "myPackageName")
>
> and you can use that in your call to system().
>
> The down side is that you will have to ensure that the program is built
> in a portable way. So if you won the C code, it is almost the same thing
> as building a DLL and using .C/.Call.
>
> HTH
>
> D.
>
>
>
> Walton A. Green wrote:
> > R-helpers,
> >
> > Is there an easy way to call an external (C) program using .C or .Call
> > without including the code in a package. I know how to do it using
> > system(), but that doesn't seem to be a permanent or portable solution.
> > Initially I tried:
> >
> > .Call('filepath.to.c.function', arg1)
> >
> > and got this error:
> >
> > Error in .Call("filepath.to.c.function", "arg1", :
> > "C" function name not in load table
> >
> > So read the section on foreign language interfaces in the Writing R
> > Extensions manual but when I tried:
> >
> > dyn.load('filepath.to.c.function')
> >
> > I got:
> >
> > Error in dyn.load(x, as.logical(local), as.logical(now)) :
> > unable to load shared library 'filepath.to.c.function':
> > dlopen(filepath.to.c.function, 6): bad external relocation length
> >
> > Do you need to run R_registerRoutines before dyn.load()? I couldn't find
> > any mention of this error on the web....
> >
> > Walton
> >
> > platform powerpc-apple-darwin7.9.0
> > arch powerpc
> > os darwin7.9.0
> > system powerpc, darwin7.9.0
> > status
> > major 2
> > minor 1.1
> > year 2005
> > month 06
> > day 20
> > language R
> >
> > ______________________________________________
> > R-help@stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help> > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html>