[R] Calling R from C (Windows)

2012-10-15 Thread BayesForever

I am trying to follow the instructions in section 8.2.2 of Writing R
extensions, to learn how to call R from C.  In this manual and at other
sites I see continual references to examples in the tests/Embedding
directory of the sources.  

There is no directory named Embedding anywhere in my 2.13.1 install of R. 
Am I missing components that I need to call R from C, or am I
misunderstanding the meaning of the tests/Embedding directory of the
sources?



--
View this message in context: 
http://r.789695.n4.nabble.com/Calling-R-from-C-Windows-tp4646285.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Calling R from C (Windows)

2012-10-15 Thread Simon Knapp
Yes.

Your looking at R_HOME (the installation directory), not the
directory of the sources.

On Tue, Oct 16, 2012 at 10:08 AM, BayesForever
andrew.mor...@verizon.net wrote:

 I am trying to follow the instructions in section 8.2.2 of Writing R
 extensions, to learn how to call R from C.  In this manual and at other
 sites I see continual references to examples in the tests/Embedding
 directory of the sources.

 There is no directory named Embedding anywhere in my 2.13.1 install of R.
 Am I missing components that I need to call R from C, or am I
 misunderstanding the meaning of the tests/Embedding directory of the
 sources?



 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Calling-R-from-C-Windows-tp4646285.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] calling R from C

2011-06-25 Thread Desi Ap
I read R extensions on calling R within c code. I am on windows vista, cygwin 
and R-2.13.0.I can compile  link the c code with following commands$gcc 
-I/cygdrive/c/Progra~1/R/R-2.13.0/include -c -ggdb Rhello.c
gcc-L/cygdrive/c/Progra~1/R/R-2.13.0/bin/i386 -oRhello Rhello.o -lR
However I cant run the resulting .exe file with following command
LD_LIBRARY_PATH=/cygdrive/c/Progra~1/R/R-2.13.0/bin R_HOME=/cygdrive/c/Progra
~1/R/R-2.13.0 ./Rhello.exe
I get a pop up window and it just hangs when I try to run exe file. I assume 
calling R via c program on cygwin/windowsvista is known to be working.
if so, can some one comment on how to run above exe file.
thanks-kris

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] calling R from C

2011-06-25 Thread David Winsemius


On Jun 25, 2011, at 11:18 AM, Desi Ap wrote:

I read R extensions on calling R within c code. I am on windows  
vista, cygwin and R-2.13.0.I can compile  link the c code with  
following commands$gcc -I/cygdrive/c/Progra~1/R/R-2.13.0/include -c - 
ggdb Rhello.c

gcc-L/cygdrive/c/Progra~1/R/R-2.13.0/bin/i386 -oRhello Rhello.o -lR
However I cant run the resulting .exe file with following command
LD_LIBRARY_PATH=/cygdrive/c/Progra~1/R/R-2.13.0/bin R_HOME=/cygdrive/ 
c/Progra

~1/R/R-2.13.0 ./Rhello.exe
I get a pop up window and it just hangs when I try to run exe file.  
I assume calling R via c program on cygwin/windowsvista is known to  
be working.

if so, can some one comment on how to run above exe file.


It would be courteous posting behavior to put people on notice that  
this is an identical question to one posed earlier at SO:

http://stackoverflow.com/questions/6478761/problem-running-c-code-that-has-r-in-it

--
David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] calling R from C

2011-06-25 Thread Barry Rowlingson
On Sat, Jun 25, 2011 at 4:18 PM, Desi Ap des...@yahoo.com wrote:
 I read R extensions on calling R within c code. I am on windows vista, cygwin 
 and R-2.13.0.I can compile  link the c code with following commands$gcc 
 -I/cygdrive/c/Progra~1/R/R-2.13.0/include -c -ggdb Rhello.c
 gcc-L/cygdrive/c/Progra~1/R/R-2.13.0/bin/i386 -oRhello Rhello.o -lR
 However I cant run the resulting .exe file with following command
 LD_LIBRARY_PATH=/cygdrive/c/Progra~1/R/R-2.13.0/bin R_HOME=/cygdrive/c/Progra
 ~1/R/R-2.13.0 ./Rhello.exe
 I get a pop up window and it just hangs when I try to run exe file. I assume 
 calling R via c program on cygwin/windowsvista is known to be working.
 if so, can some one comment on how to run above exe file.
 thanks-kris

 You need to read the documentation to discover that maybe you should
be using the right tools. Namely MinGW and not Cygwin. Unless you've
managed to compile the whole of R using cygwin of course...

 I hope having identical responses to mailing list messages and SO
questions isn't as annoying as seeing identical questions posted to
each is to everyone on the list...

 Barry

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] calling R from C

2011-06-25 Thread Desi Ap
hey David:Newbie here. will avoid duplicates next time. thanks...
-krishna

--- On Sat, 6/25/11, David Winsemius dwinsem...@comcast.net wrote:

From: David Winsemius dwinsem...@comcast.net
Subject: Re: [R] calling R from C
To: Desi Ap des...@yahoo.com
Cc: r-help@r-project.org
Date: Saturday, June 25, 2011, 10:38 PM


On Jun 25, 2011, at 11:18 AM, Desi Ap wrote:

 I read R extensions on calling R within c code. I am on windows vista, cygwin 
 and R-2.13.0.I can compile  link the c code with following commands$gcc 
 -I/cygdrive/c/Progra~1/R/R-2.13.0/include -c -ggdb Rhello.c
 gcc-L/cygdrive/c/Progra~1/R/R-2.13.0/bin/i386 -oRhello Rhello.o -lR
 However I cant run the resulting .exe file with following command
 LD_LIBRARY_PATH=/cygdrive/c/Progra~1/R/R-2.13.0/bin R_HOME=/cygdrive/c/Progra
 ~1/R/R-2.13.0 ./Rhello.exe
 I get a pop up window and it just hangs when I try to run exe file. I assume 
 calling R via c program on cygwin/windowsvista is known to be working.
 if so, can some one comment on how to run above exe file.

It would be courteous posting behavior to put people on notice that this is an 
identical question to one posed earlier at SO:
http://stackoverflow.com/questions/6478761/problem-running-c-code-that-has-r-in-it

--David Winsemius, MD
West Hartford, CT


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Calling R from c in Windows XP

2010-03-27 Thread dkStevens

I'm searching for answers to four questions (I've been searching the net for
hours...)

In Windows XP, is it possible to call R functions from a c program? (I've
found examples for Linux/Unix but not Windows)

If so, is there a simple example to get started using gcc with R-2.10.0?

If so, is it possible to write a simple interface using a c dll to call R
functions from a Visual Basic.net program?

If so, is there a simple example?

Thanks to all
-- 
View this message in context: 
http://n4.nabble.com/Calling-R-from-c-in-Windows-XP-tp1693440p1693440.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Calling R from c in Windows XP

2010-03-27 Thread Khanh Nguyen
Have you looked at RInside ?

-k

On Sat, Mar 27, 2010 at 10:53 AM, dkStevens david.stev...@usu.edu wrote:

 I'm searching for answers to four questions (I've been searching the net for
 hours...)

 In Windows XP, is it possible to call R functions from a c program? (I've
 found examples for Linux/Unix but not Windows)

 If so, is there a simple example to get started using gcc with R-2.10.0?

 If so, is it possible to write a simple interface using a c dll to call R
 functions from a Visual Basic.net program?

 If so, is there a simple example?

 Thanks to all
 --
 View this message in context: 
 http://n4.nabble.com/Calling-R-from-c-in-Windows-XP-tp1693440p1693440.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Calling R from c in Windows XP

2010-03-27 Thread Erich Neuwirth
If you want to call R from within VB.NET you might want to look at
the statconnDCOM server (available at rcom.univie.ac.at)
It wraps R into a (D)COM server and therefore allows any (D)COM client
to access R on windows. VB.NET is a (D)COM client.



On 3/27/2010 3:53 PM, dkStevens wrote:
 
 I'm searching for answers to four questions (I've been searching the net for
 hours...)
 
 In Windows XP, is it possible to call R functions from a c program? (I've
 found examples for Linux/Unix but not Windows)
 
 If so, is there a simple example to get started using gcc with R-2.10.0?
 
 If so, is it possible to write a simple interface using a c dll to call R
 functions from a Visual Basic.net program?
 
 If so, is there a simple example?
 
 Thanks to all

-- 
Erich Neuwirth, University of Vienna
Faculty of Computer Science
Computer Supported Didactics Working Group
Visit our SunSITE at http://sunsite.univie.ac.at
Phone: +43-1-4277-39464 Fax: +43-1-4277-39459

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Calling R from c in Windows XP

2010-03-27 Thread dkStevens

I've looked at this a bit and it seems ok, if not a little convoluted. We're
trying to stay away from com objects, so I was hoping for something more
direct. I've seen some examples (e.g. RInside) but can't get them to work
-too many include files, etc. that I can't find.
-- 
View this message in context: 
http://n4.nabble.com/Calling-R-from-c-in-Windows-XP-tp1693440p1693480.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Calling R from c in Windows XP

2010-03-27 Thread dkStevens

I have - but when I tried their simple example no luck - too many missing
include files to chase down. I'm looking for something more direct, I guess,
that I have a little control over.
-- 
View this message in context: 
http://n4.nabble.com/Calling-R-from-c-in-Windows-XP-tp1693440p1693478.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Calling R from c in Windows XP

2010-03-27 Thread Khanh Nguyen
What examples are you talking about. You only need to include
RInside.h... More information is here
http://dirk.eddelbuettel.com/code/rinside.html

The other external thing you need is the Rcpp package, which you can
do with install.packages('Rcpp')



On Sat, Mar 27, 2010 at 11:40 AM, dkStevens david.stev...@usu.edu wrote:

 I've looked at this a bit and it seems ok, if not a little convoluted. We're
 trying to stay away from com objects, so I was hoping for something more
 direct. I've seen some examples (e.g. RInside) but can't get them to work
 -too many include files, etc. that I can't find.
 --
 View this message in context: 
 http://n4.nabble.com/Calling-R-from-c-in-Windows-XP-tp1693440p1693480.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Calling R from c in Windows XP

2010-03-27 Thread dkStevens

This may simply expose my ignorance in this type of coding, but,
unfortunately it's not that simple because I did using the RInside.h and
received several screens of error messages from gcc telling me that it
couldn't find the include file and the scores of additional include files
that rinside.h referred to.  After much editing to point to these files
those error messages went away but more screens of error messages followed.
This using the four-line 'hello world' example that is provided by the
RInside authors. So I'm faced with hours of chasing these down or finding a
simpler example. I'd rather the latter, hence my post.
-- 
View this message in context: 
http://n4.nabble.com/Calling-R-from-c-in-Windows-XP-tp1693440p1693538.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Calling R from c in Windows XP

2010-03-27 Thread Dirk Eddelbuettel

On 27 March 2010 at 11:50, Khanh Nguyen wrote:
| What examples are you talking about. You only need to include
| RInside.h... More information is here
| http://dirk.eddelbuettel.com/code/rinside.html

Khanh is quite correct: RInside is self-contained. It also doesn't get much
simpler than the examples we show.

| The other external thing you need is the Rcpp package, which you can
| do with install.packages('Rcpp')

It used to have a Suggests: on Rcpp but now has a Depends: on it. That said,
a few things:

   - David probably chose to ignore the big bold signs that tell him to use
 gcc (in the mingw implementation).  Insisting on visual whatever buys
 you nothing as R requires gcc and mingw. No ifs or buts. gcc/g++ it is.

   - We made a lot of changes between RInside 0.2.1 (which worked on Windows) 
 and the current 0.2.2 for which the example build but then segfault. I
 suspect some initialization of static variables issue or something like
 it. I'd welcome debugging assistance from anyone with more interest in
 Windows than Romain and I have.

   - Again, a working example is provided by RInside 0.2.1, possibly coupled
 with a matching Rcpp release as e.g. 0.7.1

   - Other simpler examples are provided in the R sources under tests/Embedding

Dirk
 
| On Sat, Mar 27, 2010 at 11:40 AM, dkStevens david.stev...@usu.edu wrote:
| 
|  I've looked at this a bit and it seems ok, if not a little convoluted. We're
|  trying to stay away from com objects, so I was hoping for something more
|  direct. I've seen some examples (e.g. RInside) but can't get them to work
|  -too many include files, etc. that I can't find.
|  --
|  View this message in context: 
http://n4.nabble.com/Calling-R-from-c-in-Windows-XP-tp1693440p1693480.html
|  Sent from the R help mailing list archive at Nabble.com.
| 
|  __
|  R-help@r-project.org mailing list
|  https://stat.ethz.ch/mailman/listinfo/r-help
|  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
|  and provide commented, minimal, self-contained, reproducible code.
| 
| 
| __
| R-help@r-project.org mailing list
| https://stat.ethz.ch/mailman/listinfo/r-help
| PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
| and provide commented, minimal, self-contained, reproducible code.

-- 
  Registration is open for the 2nd International conference R / Finance 2010
  See http://www.RinFinance.com for details, and see you in Chicago in April!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Calling R from c in Windows XP

2010-03-27 Thread Dirk Eddelbuettel

On 27 March 2010 at 09:02, dkStevens wrote:
| This may simply expose my ignorance in this type of coding, but,
| unfortunately it's not that simple because I did using the RInside.h and
| received several screens of error messages from gcc telling me that it
| couldn't find the include file and the scores of additional include files
| that rinside.h referred to.  After much editing to point to these files
| those error messages went away but more screens of error messages followed.
| This using the four-line 'hello world' example that is provided by the
| RInside authors. So I'm faced with hours of chasing these down or finding a
| simpler example. I'd rather the latter, hence my post.

Try to look inside the installed package RInside and to fine the directory
examples/ -- it contains a directory standard/ with nine example files
rinside_sample[0-8] plus two further tests (and another directory mpi/ which
we ignore for now)

On a correctly setup computer, building the examples programs in the
directory examples/standard is as easy as saying

   make -f Makefile.win # you need to point make to the Windows makefile

which builds all executables (on my windows box at work).  No editing required.

This is getting off-topic for r-help as you are asked by the posting guide to
contact package authors (ie Romain or me). We usually suggest to take these
RInside discussions to the rcpp-devel list --- see the R-Forge pages for Rcpp.

Dirk

-- 
  Registration is open for the 2nd International conference R / Finance 2010
  See http://www.RinFinance.com for details, and see you in Chicago in April!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Calling R from c in Windows XP

2010-03-27 Thread dkStevens

Thanks for your prompt response. Apparently my problem is with my R or 
Windows setup. When I followed the advice in your return email, here's 
the result. I've been an R user for a number of years and have 
installed/uninstalled several versions, plus I've installed MinGW, 
RTools, gcc/gfortran, and a number of R-related packages. I must have 
messed something up. Is there a pointer to the proper configuration? 
Today I reinstalled RInside and Rcpp before trying the make below.  
Thanks, and I'll be sure to post properly in the future. I didn't start 
at RInside, I started with 'how can I call R from a c program.

Regards

David Stevens


C:\Program Files\R\R-2.10.0\library\RInside\examples\standardmake -f 
makefile.win
process_begin: CreateProcess(NULL, /bin/R CMD config --cppflags, ...) 
failed.
process_begin: CreateProcess(NULL, /bin/R CMD config --ldflags, ...) failed.
process_begin: CreateProcess(NULL, /bin/R CMD config BLAS_LIBS, ...) failed.
process_begin: CreateProcess(NULL, /bin/R CMD config LAPACK_LIBS, ...) 
failed.
/bin/R: not found
/bin/R: not found
/bin/R: not found
/bin/R: not found
process_begin: CreateProcess(NULL, /bin/R CMD config CXX, ...) failed.
process_begin: CreateProcess(NULL, /bin/R CMD config CPPFLAGS, ...) failed.
process_begin: CreateProcess(NULL, /bin/R CMD config CXXFLAGS, ...) failed.
process_begin: CreateProcess(NULL, /bin/R CMD config CXX, ...) failed.
Wall  -s  rinside_sample0.cpp   -o rinside_sample0
process_begin: CreateProcess(NULL, Wall -s rinside_sample0.cpp -o 
rinside_sample0, ...) failed.
make (e=2): The system cannot find the file specified.
make: [rinside_sample0] Error 2 (ignored)
Wall  -s  rinside_sample1.cpp   -o rinside_sample1
process_begin: CreateProcess(NULL, Wall -s rinside_sample1.cpp -o 
rinside_sample1, ...) failed.
make (e=2): The system cannot find the file specified.
make: [rinside_sample1] Error 2 (ignored)
Wall  -s  rinside_sample2.cpp   -o rinside_sample2
process_begin: CreateProcess(NULL, Wall -s rinside_sample2.cpp -o 
rinside_sample2, ...) failed.
make (e=2): The system cannot find the file specified.
make: [rinside_sample2] Error 2 (ignored)
Wall  -s  rinside_sample3.cpp   -o rinside_sample3
process_begin: CreateProcess(NULL, Wall -s rinside_sample3.cpp -o 
rinside_sample3, ...) failed.
make (e=2): The system cannot find the file specified.
make: [rinside_sample3] Error 2 (ignored)
Wall  -s  rinside_sample4.cpp   -o rinside_sample4
process_begin: CreateProcess(NULL, Wall -s rinside_sample4.cpp -o 
rinside_sample4, ...) failed.
make (e=2): The system cannot find the file specified.
make: [rinside_sample4] Error 2 (ignored)
Wall  -s  rinside_sample5.cpp   -o rinside_sample5
process_begin: CreateProcess(NULL, Wall -s rinside_sample5.cpp -o 
rinside_sample5, ...) failed.
make (e=2): The system cannot find the file specified.
make: [rinside_sample5] Error 2 (ignored)
Wall  -s  rinside_sample6.cpp   -o rinside_sample6
process_begin: CreateProcess(NULL, Wall -s rinside_sample6.cpp -o 
rinside_sample6, ...) failed.
make (e=2): The system cannot find the file specified.
make: [rinside_sample6] Error 2 (ignored)
Wall  -s  rinside_sample7.cpp   -o rinside_sample7
process_begin: CreateProcess(NULL, Wall -s rinside_sample7.cpp -o 
rinside_sample7, ...) failed.
make (e=2): The system cannot find the file specified.
make: [rinside_sample7] Error 2 (ignored)
Wall  -s  rinside_sample8.cpp   -o rinside_sample8
process_begin: CreateProcess(NULL, Wall -s rinside_sample8.cpp -o 
rinside_sample8, ...) failed.
make (e=2): The system cannot find the file specified.
make: [rinside_sample8] Error 2 (ignored)
Wall  -s  rinside_test0.cpp   -o rinside_test0
process_begin: CreateProcess(NULL, Wall -s rinside_test0.cpp -o 
rinside_test0, ...) failed.
make (e=2): The system cannot find the file specified.
make: [rinside_test0] Error 2 (ignored)
Wall  -s  rinside_test1.cpp   -o rinside_test1
process_begin: CreateProcess(NULL, Wall -s rinside_test1.cpp -o 
rinside_test1, ...) failed.
make (e=2): The system cannot find the file specified.
make: [rinside_test1] Error 2 (ignored)


Dirk Eddelbuettel [via R] wrote:

 On 27 March 2010 at 09:02, dkStevens wrote:
 | This may simply expose my ignorance in this type of coding, but,
 | unfortunately it's not that simple because I did using the RInside.h 
 and
 | received several screens of error messages from gcc telling me that it
 | couldn't find the include file and the scores of additional include 
 files
 | that rinside.h referred to.  After much editing to point to these files
 | those error messages went away but more screens of error messages 
 followed.
 | This using the four-line 'hello world' example that is provided by the
 | RInside authors. So I'm faced with hours of chasing these down or 
 finding a
 | simpler example. I'd rather the latter, hence my post.

 Try to look inside the installed package RInside and to fine the 
 directory
 examples/ -- it contains a directory 

Re: [R] Calling R from c in Windows XP

2010-03-27 Thread Dirk Eddelbuettel

David,

On 27 March 2010 at 10:08, dkStevens wrote:
| Thanks for your prompt response. Apparently my problem is with my R or 
| Windows setup. When I followed the advice in your return email, here's 
| the result.

I will eat my hat. What you show I had too -- you need to define 
the environment variable R_HOME which is used all over Makefile.win.  I have
this in there commented out:

   #R_HOME :=   $(shell R RHOME)

as I couldn't get it to work. [ I one used 'R CMD ...' one gets R_HOME for
free but not here. ]

So my bad and please re-try with R_HOME

| I've been an R user for a number of years and have 
| installed/uninstalled several versions, plus I've installed MinGW, 
| RTools, gcc/gfortran, and a number of R-related packages. I must have 
| messed something up. Is there a pointer to the proper configuration? 
| Today I reinstalled RInside and Rcpp before trying the make below.  
| Thanks, and I'll be sure to post properly in the future. I didn't start 
| at RInside, I started with 'how can I call R from a c program.

Sounds good.  As per my previous email you may run into segfaults on Windows
with the current version. Try backtracking to RInside 0.2.1 and Rcpp 0.7.1
(from the respective Archive/ sections on CRAN) which should work.  We could
then try to close the gap between those working versions and the current code
to see what upsets.  Or do what Romain and I do and stay on operating systems
that have a lower- or uppercase X in their name. ;-)

Sorry again for the earlier misinformation. I forgot this little detail.

Lastly, we really should move this to rcpp-devel 

Dirk
 
| Regards
| 
| David Stevens
| 
| 
| C:\Program Files\R\R-2.10.0\library\RInside\examples\standardmake -f 
| makefile.win
| process_begin: CreateProcess(NULL, /bin/R CMD config --cppflags, ...) 
| failed.
| process_begin: CreateProcess(NULL, /bin/R CMD config --ldflags, ...) failed.
| process_begin: CreateProcess(NULL, /bin/R CMD config BLAS_LIBS, ...) failed.
| process_begin: CreateProcess(NULL, /bin/R CMD config LAPACK_LIBS, ...) 
| failed.
| /bin/R: not found
| /bin/R: not found
| /bin/R: not found
| /bin/R: not found
| process_begin: CreateProcess(NULL, /bin/R CMD config CXX, ...) failed.
| process_begin: CreateProcess(NULL, /bin/R CMD config CPPFLAGS, ...) failed.
| process_begin: CreateProcess(NULL, /bin/R CMD config CXXFLAGS, ...) failed.
| process_begin: CreateProcess(NULL, /bin/R CMD config CXX, ...) failed.
| Wall  -s  rinside_sample0.cpp   -o rinside_sample0
| process_begin: CreateProcess(NULL, Wall -s rinside_sample0.cpp -o 
| rinside_sample0, ...) failed.
| make (e=2): The system cannot find the file specified.
| make: [rinside_sample0] Error 2 (ignored)
| Wall  -s  rinside_sample1.cpp   -o rinside_sample1
| process_begin: CreateProcess(NULL, Wall -s rinside_sample1.cpp -o 
| rinside_sample1, ...) failed.
| make (e=2): The system cannot find the file specified.
| make: [rinside_sample1] Error 2 (ignored)
| Wall  -s  rinside_sample2.cpp   -o rinside_sample2
| process_begin: CreateProcess(NULL, Wall -s rinside_sample2.cpp -o 
| rinside_sample2, ...) failed.
| make (e=2): The system cannot find the file specified.
| make: [rinside_sample2] Error 2 (ignored)
| Wall  -s  rinside_sample3.cpp   -o rinside_sample3
| process_begin: CreateProcess(NULL, Wall -s rinside_sample3.cpp -o 
| rinside_sample3, ...) failed.
| make (e=2): The system cannot find the file specified.
| make: [rinside_sample3] Error 2 (ignored)
| Wall  -s  rinside_sample4.cpp   -o rinside_sample4
| process_begin: CreateProcess(NULL, Wall -s rinside_sample4.cpp -o 
| rinside_sample4, ...) failed.
| make (e=2): The system cannot find the file specified.
| make: [rinside_sample4] Error 2 (ignored)
| Wall  -s  rinside_sample5.cpp   -o rinside_sample5
| process_begin: CreateProcess(NULL, Wall -s rinside_sample5.cpp -o 
| rinside_sample5, ...) failed.
| make (e=2): The system cannot find the file specified.
| make: [rinside_sample5] Error 2 (ignored)
| Wall  -s  rinside_sample6.cpp   -o rinside_sample6
| process_begin: CreateProcess(NULL, Wall -s rinside_sample6.cpp -o 
| rinside_sample6, ...) failed.
| make (e=2): The system cannot find the file specified.
| make: [rinside_sample6] Error 2 (ignored)
| Wall  -s  rinside_sample7.cpp   -o rinside_sample7
| process_begin: CreateProcess(NULL, Wall -s rinside_sample7.cpp -o 
| rinside_sample7, ...) failed.
| make (e=2): The system cannot find the file specified.
| make: [rinside_sample7] Error 2 (ignored)
| Wall  -s  rinside_sample8.cpp   -o rinside_sample8
| process_begin: CreateProcess(NULL, Wall -s rinside_sample8.cpp -o 
| rinside_sample8, ...) failed.
| make (e=2): The system cannot find the file specified.
| make: [rinside_sample8] Error 2 (ignored)
| Wall  -s  rinside_test0.cpp   -o rinside_test0
| process_begin: CreateProcess(NULL, Wall -s rinside_test0.cpp -o 
| rinside_test0, ...) failed.
| make (e=2): The system cannot find the file 

Re: [R] Calling R from c in Windows XP

2010-03-27 Thread Martin Morgan
On 03/27/2010 07:53 AM, dkStevens wrote:
 
 I'm searching for answers to four questions (I've been searching the net for
 hours...)
 
 In Windows XP, is it possible to call R functions from a c program? (I've
 found examples for Linux/Unix but not Windows)
 
 If so, is there a simple example to get started using gcc with R-2.10.0?

Up to this point, the answer is in Writing R Extensions, sections 8.1
and 8.2 (which has a kind of implicit dependency on 8.1). A minimal file
might be

embed_win.c:

#include Rembedded.h

int main(int argc, char *argv[])
{
Rf_initEmbeddedR(argc, argv);

run_Rmainloop();

Rf_endEmbeddedR(0);
return 0;
}

and after discovering appropriate compiler args with

R CMD config --cppflags
R CMD config --ldflags

one might (modulo line wrapping in email clients :()

Z:\Home\tmpgcc -IC:/PROGRA~1/R/R-211~1.0DE/include
  -LC:/PROGRA~1/R/R-211~1.0DE/bin -lR embed_win.c

and then

Z:\Home\tmpa --vanilla
 x = 1:10
 q()

There are more examples in

https://svn.r-project.org/R/trunk/tests/Embedding

Martin

 
 If so, is it possible to write a simple interface using a c dll to call R
 functions from a Visual Basic.net program?
 
 If so, is there a simple example?
 
 Thanks to all


-- 
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Calling R from C - part way there but need a push!

2008-04-30 Thread Jeffrey Horner

Maximillian Murphy wrote on 04/29/2008 11:19 AM:


Dear All,


I've read the manual on Writing R Extensions and in particular the 
part on calling R from C.  (Most of the manual is about calling C from 
R, not the other way around.)


The good news is that I can now call _some_ R from C, specifically the R 
functions which have C header files.  However it isn't clear to me how 
to call R functions that are written in R.  I imagine that there is a 
standard C function of the form


Call_r_from_C(package name, Rfunction name as a string, arg1, arg2, 
...);


where arg1 etc are standardised ways of representing R data structures 
in C.  However I haven't been able to find such a function prototype in 
the R include/*.h files.  See footnote (1).  Can you point me in the 
right direction please?  Is there a set of examples somewhere that I can 
peruse?



Does R keep any state when being called from C?  Should I think of it as 
being a co-process, so I can make consecutive calls to it and expect it 
to remember previous calls?  I'm thinking of a sequence of calls such as 
load library,  load R code from a file of my own, set value of x, 
make a call and read the values back into my C program?



Help is much appreciated.


I would recommend studying the examples found in the tests/Embedding 
directory from the R sources. For instance, the following is from 
RNamedCall.c:


 /*
  Call the function foo() with 3 arguments, 2 of which
  are named.
   foo(pch=+, id = 123, c(T,F))

  Note that PrintValue() of the expression seg-faults.
  We have to set the print name correctly.
*/

void
bar1()
{
SEXP fun, pch;
SEXP e;

PROTECT(e = allocVector(LANGSXP, 4));
fun = findFun(install(foo), R_GlobalEnv);
if(fun == R_NilValue) {
	fprintf(stderr, No definition for function foo. Source foo.R and save 
the session.\n);

UNPROTECT(1);
exit(1);
}
SETCAR(e, fun);

SETCADR(e, mkString(+));
SET_TAG(CDR(e), install(pch));

SETCADDR(e, ScalarInteger(123));
SET_TAG(CDR(CDR(e)), install(id));

pch = allocVector(LGLSXP, 2);
LOGICAL(pch)[0] = TRUE;
LOGICAL(pch)[1] = FALSE;
SETCADDDR(e, pch);

PrintValue(e);
eval(e, R_GlobalEnv);

SETCAR(e, install(foo));
PrintValue(e);
R_tryEval(e, R_GlobalEnv, NULL);

UNPROTECT(1);
}

Best,

Jeff




Regards, Max


(1) The most likely include file is Rinterface.h and within that the 
most likely candidates seem to be:

extern int  (*ptr_R_ReadConsole)(const char *, unsigned char *, int, int);
extern void (*ptr_R_WriteConsole)(const char *, int);
extern void (*ptr_R_WriteConsoleEx)(const char *, int, int);

but it turns out that they assume that R is running the terminal and 
these are requests to R to display or read from R's console.  R isn't 
acting as the back end being given work and returning answers.


(2) Googling calling r from c yields precisely five hits, most of 
which just point back at the R extensions document with vague It's in 
there somewhere's.  I've looked!


(3) Leads suggested by help.search(C)
Foreign(base):
 Foreign Function Interface  Functions to make calls to compiled 
code that has been loaded into R.


.Internal(base) Call an Internal Function
 '.Internal' performs a call to an internal code which is built in
 to the R interpreter.

 Only true R wizards should even consider using this function, and
 only R developers can add to the list of internal functions.

 (Definitely not me!)

.Primitive(base)Call a Primitive Internal Function

 The advantage of '.Primitive' over '.Internal' functions is the
 potential efficiency of argument passing.

(4) R code that I have called successfully is that with prototypes 
defined in e.g. include/R_ext/Applic.h


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.



--
http://biostat.mc.vanderbilt.edu/JeffreyHorner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Calling R from C - part way there but need a push!

2008-04-29 Thread Maximillian Murphy


Dear All,


I've read the manual on Writing R Extensions and in particular the  
part on calling R from C.  (Most of the manual is about calling C  
from R, not the other way around.)


The good news is that I can now call _some_ R from C, specifically  
the R functions which have C header files.  However it isn't clear to  
me how to call R functions that are written in R.  I imagine that  
there is a standard C function of the form


Call_r_from_C(package name, Rfunction name as a string, arg1,  
arg2, ...);


where arg1 etc are standardised ways of representing R data  
structures in C.  However I haven't been able to find such a function  
prototype in the R include/*.h files.  See footnote (1).  Can you  
point me in the right direction please?  Is there a set of examples  
somewhere that I can peruse?



Does R keep any state when being called from C?  Should I think of it  
as being a co-process, so I can make consecutive calls to it and  
expect it to remember previous calls?  I'm thinking of a sequence of  
calls such as load library,  load R code from a file of my own,  
set value of x, make a call and read the values back into my C  
program?



Help is much appreciated.


Regards, Max


(1) The most likely include file is Rinterface.h and within that the  
most likely candidates seem to be:
extern int  (*ptr_R_ReadConsole)(const char *, unsigned char *, int,  
int);

extern void (*ptr_R_WriteConsole)(const char *, int);
extern void (*ptr_R_WriteConsoleEx)(const char *, int, int);

but it turns out that they assume that R is running the terminal and  
these are requests to R to display or read from R's console.  R isn't  
acting as the back end being given work and returning answers.


(2) Googling calling r from c yields precisely five hits, most of  
which just point back at the R extensions document with vague It's  
in there somewhere's.  I've looked!


(3) Leads suggested by help.search(C)
Foreign(base):
 Foreign Function Interface  Functions to make calls to compiled  
code that has been loaded into R.


.Internal(base) Call an Internal Function
 '.Internal' performs a call to an internal code which is built in
 to the R interpreter.

 Only true R wizards should even consider using this function, and
 only R developers can add to the list of internal functions.

 (Definitely not me!)

.Primitive(base)Call a Primitive Internal Function

 The advantage of '.Primitive' over '.Internal' functions is the
 potential efficiency of argument passing.

(4) R code that I have called successfully is that with prototypes  
defined in e.g. include/R_ext/Applic.h


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Calling R from C - part way there but need a push!

2008-04-29 Thread Duncan Murdoch

On 29/04/2008 12:19 PM, Maximillian Murphy wrote:

Dear All,


I've read the manual on Writing R Extensions and in particular the  
part on calling R from C.  (Most of the manual is about calling C  
from R, not the other way around.)


The good news is that I can now call _some_ R from C, specifically  
the R functions which have C header files.  However it isn't clear to  
me how to call R functions that are written in R.  I imagine that  
there is a standard C function of the form


Call_r_from_C(package name, Rfunction name as a string, arg1,  
arg2, ...);


Not really.  eval() is the main function to call from C.  You construct 
an R expression, then evaluate it.


where arg1 etc are standardised ways of representing R data  
structures in C.  However I haven't been able to find such a function  
prototype in the R include/*.h files.  See footnote (1).  Can you  
point me in the right direction please?  Is there a set of examples  
somewhere that I can peruse?


Section 5.10 (Evaluating R expressions from C) of the Writing R 
Extensions manual gives a couple of examples.



Does R keep any state when being called from C?  Should I think of it  
as being a co-process, so I can make consecutive calls to it and  
expect it to remember previous calls?  I'm thinking of a sequence of  
calls such as load library,  load R code from a file of my own,  
set value of x, make a call and read the values back into my C  
program?


The normal way to do it is to let R be in charge, and only occasionally 
call out to C:  so then R keeps its state.  What you are trying to do 
sounds more like writing a new front-end to R, which is much more 
involved:  see Chapter 8 of that manual.


Duncan Murdoch



Help is much appreciated.


Regards, Max


(1) The most likely include file is Rinterface.h and within that the  
most likely candidates seem to be:
extern int  (*ptr_R_ReadConsole)(const char *, unsigned char *, int,  
int);

extern void (*ptr_R_WriteConsole)(const char *, int);
extern void (*ptr_R_WriteConsoleEx)(const char *, int, int);

but it turns out that they assume that R is running the terminal and  
these are requests to R to display or read from R's console.  R isn't  
acting as the back end being given work and returning answers.


(2) Googling calling r from c yields precisely five hits, most of  
which just point back at the R extensions document with vague It's  
in there somewhere's.  I've looked!


(3) Leads suggested by help.search(C)
Foreign(base):
  Foreign Function Interface  Functions to make calls to compiled  
code that has been loaded into R.


.Internal(base) Call an Internal Function
  '.Internal' performs a call to an internal code which is built in
  to the R interpreter.

  Only true R wizards should even consider using this function, and
  only R developers can add to the list of internal functions.

  (Definitely not me!)

.Primitive(base)Call a Primitive Internal Function

  The advantage of '.Primitive' over '.Internal' functions is the
  potential efficiency of argument passing.

(4) R code that I have called successfully is that with prototypes  
defined in e.g. include/R_ext/Applic.h


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Calling R from C - part way there but need a push!

2008-04-29 Thread Maximillian Murphy



I'm afraid I haven't quite got the hang of this yet.  Here's a Hello  
World:



#include R.h
#include Rinternals.h
#include Rembedded.h
#include stdio.h


extern int R_running_as_main_program;   /* in ../unix/system.c */

int main(int ac, char **av)
{

SEXP aleph, beth;

 // R_running_as_main_program = 1; // A
 // Rf_initialize_R(ac, av);   // B
 // Rf_mainloop(); // C


 // R_running_as_main_program = 0;   // a
 // Rf_initialize_R(ac, av); // b


 // aleph = PROTECT(allocVector(VECSXP, 2)); // 1
 // aleph = Rf_mkString(hoodunnit);// 2
 // aleph = allocVector(REALSXP, 2); // 3

return 0;
}

The simple example of a front end given in Chapter 8 is obtained by  
uncommenting A, B and C, and that works fine.  It gives an  
interactive shell.


If instead I uncomment any of 1, 2 or 3 I have just a simple  
declaration and assignment similar to several I have found in the R  
source files.  The only difference I can see is that I am running in  
main() rather than in a C function that is called by R.  Yet if I try  
to run this I get a segfault.


I reasoned that when starting R probably sets up some data structures  
that are needed so I tried inserting lines a and b, but I still get a  
segfault.


Do you have any suggestions on how to proceed?

{ I need to be able to create SEXPs to feed eval().  I don't yet know  
what kind of SEXPs but I'll cross that bridge when I come to it! }


Regards, Max

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.