Re: [Rd] C vs. C++ as learning and development tool for R

2007-01-20 Thread Peter Dalgaard
Roger Bivand wrote:
 Just [use] MinGW like R [does], following the guides to the letter gets you 
 there like
 marked stones across a marsh. Leaving the path usually gets you at best
 neck deep in the mire, alternatively just bubbles. 
That's the strongest contender for a space in the fortune file I've seen 
for a while!

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] C vs. C++ as learning and development tool for R

2007-01-19 Thread Kimpel, Mark William
I have 3 years of experience with R and have an interest in becoming a
better programmer so that I might someday be able to contribute
packages. Other than R, my only experience was taking Lisp from Daniel
Friedman in the 1970's. I would like to learn either C or C++ for
several reasons:

To gain a better concept of object oriented programming so that I can
begin to use S4 methods in R.

To perhaps speed up some things I do repeatedly in R

To be able to contribute a package someday.

 

I have been doing some reading and from what I can tell R is more
compatible with C, but C++ has much greater capabilities for OO
programming.

 

I have just started reading The C++ Programming Language: Special
Edition by Bjarne Stroustrup
http://search.barnesandnoble.com/booksearch/results.asp?ATH=Bjarne+Stro
ustrupz=y , he recommends first learning C++ and then then C if
necessary, but as a developer of C++, he is probably biased.

 

I would greatly appreciate the advice of the R developers and package
contributors on this subject. C or C++?

 

Thanks,

 

Mark

 

Mark W. Kimpel MD 

 

 

Official Business Address:

 

Department of Psychiatry

Indiana University School of Medicine

PR M116

Institute of Psychiatric Research

791 Union Drive

Indianapolis, IN 46202

 

Preferred Mailing Address:

 

15032 Hunter Court

Westfield, IN  46074

 

(317) 490-5129 Work,  Mobile

 

(317) 663-0513 Home (no voice mail please)

1-(317)-536-2730 FAX


[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] C vs. C++ as learning and development tool for R

2007-01-19 Thread Duncan Murdoch
On 1/19/2007 3:55 AM, Kimpel, Mark William wrote:
 I have 3 years of experience with R and have an interest in becoming a
 better programmer so that I might someday be able to contribute
 packages. Other than R, my only experience was taking Lisp from Daniel
 Friedman in the 1970's. I would like to learn either C or C++ for
 several reasons:
 
 To gain a better concept of object oriented programming so that I can
 begin to use S4 methods in R.
 
 To perhaps speed up some things I do repeatedly in R
 
 To be able to contribute a package someday.
 
  
 
 I have been doing some reading and from what I can tell R is more
 compatible with C, but C++ has much greater capabilities for OO
 programming.
 
  
 
 I have just started reading The C++ Programming Language: Special
 Edition by Bjarne Stroustrup
 http://search.barnesandnoble.com/booksearch/results.asp?ATH=Bjarne+Stro
 ustrupz=y , he recommends first learning C++ and then then C if
 necessary, but as a developer of C++, he is probably biased.
 
  
 
 I would greatly appreciate the advice of the R developers and package
 contributors on this subject. C or C++?

For your purposes, I would recommend C.  Most example code you'll find 
is written in C, so it's easier to learn by looking at simple examples 
written by others.  The R external interface was designed with C in 
mind, so you need to tell C++ to act like C to use it.

Regarding OOP, I think the C++ style of OOP is so different from S4 that 
it would not actually be helpful in learning S4.  As far as I know, none 
of the languages that are easy to link to R use the same style of OOP.

On the other hand, taking a disciplined approach to C programming is a 
good idea (which is I think what Stroustrup had in mind).  I'd suggest 
an object oriented Pascal (e.g. Delphi) or Java if that's what you want, 
  because they are simpler than C++.  C and R are very permissive 
languages, and if you take advantage of that you can write amazingly 
sloppy and unmaintainable code.

Duncan Murdoch

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] C vs. C++ as learning and development tool for R

2007-01-19 Thread Gabor Grothendieck
You don't necessarily need to know C or C++ to write an R package.
Many (maybe most) R packages only use R.

On 1/19/07, Kimpel, Mark William [EMAIL PROTECTED] wrote:
 I have 3 years of experience with R and have an interest in becoming a
 better programmer so that I might someday be able to contribute
 packages. Other than R, my only experience was taking Lisp from Daniel
 Friedman in the 1970's. I would like to learn either C or C++ for
 several reasons:

 To gain a better concept of object oriented programming so that I can
 begin to use S4 methods in R.

 To perhaps speed up some things I do repeatedly in R

 To be able to contribute a package someday.



 I have been doing some reading and from what I can tell R is more
 compatible with C, but C++ has much greater capabilities for OO
 programming.



 I have just started reading The C++ Programming Language: Special
 Edition by Bjarne Stroustrup
 http://search.barnesandnoble.com/booksearch/results.asp?ATH=Bjarne+Stro
 ustrupz=y , he recommends first learning C++ and then then C if
 necessary, but as a developer of C++, he is probably biased.



 I would greatly appreciate the advice of the R developers and package
 contributors on this subject. C or C++?



 Thanks,



 Mark



 Mark W. Kimpel MD





 Official Business Address:



 Department of Psychiatry

 Indiana University School of Medicine

 PR M116

 Institute of Psychiatric Research

 791 Union Drive

 Indianapolis, IN 46202



 Preferred Mailing Address:



 15032 Hunter Court

 Westfield, IN  46074



 (317) 490-5129 Work,  Mobile



 (317) 663-0513 Home (no voice mail please)

 1-(317)-536-2730 FAX


[[alternative HTML version deleted]]

 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel


__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] C vs. C++ as learning and development tool for R

2007-01-19 Thread Ramon Diaz-Uriarte
Dear Mark,

On Friday 19 January 2007 09:55, Kimpel, Mark William wrote:
 I have 3 years of experience with R and have an interest in becoming a
 better programmer so that I might someday be able to contribute
 packages. Other than R, my only experience was taking Lisp from Daniel
 Friedman in the 1970's. I would like to learn either C or C++ for
 several reasons:

 To gain a better concept of object oriented programming so that I can
 begin to use S4 methods in R.


I do not think C++ is the best idea if you are learning it to understand the 
OOP of R. The OOP of R is probably closer to that of CLOS (the common lisp 
object system) than C++ and Java.

It might be better to directly go ahead and look for documentation specificaly 
about R's OOP.

 To perhaps speed up some things I do repeatedly in R

 To be able to contribute a package someday.



 I have been doing some reading and from what I can tell R is more
 compatible with C, but C++ has much greater capabilities for OO
 programming.



 I have just started reading The C++ Programming Language: Special
 Edition by Bjarne Stroustrup
 http://search.barnesandnoble.com/booksearch/results.asp?ATH=Bjarne+Stro
 ustrupz=y , he recommends first learning C++ and then then C if
 necessary, but as a developer of C++, he is probably biased.



 I would greatly appreciate the advice of the R developers and package
 contributors on this subject. C or C++?



I'd recommend C instead of C++: C++ is a huge language and it is somewhat 
easier to interface C than C++ from R. (In non-R stuff I prefer to use C++ 
better than C, even if just as in C++as a better C, but this probably is 
not a reasonable reason to learn C++).  

HTH,

R.




 Thanks,



 Mark



 Mark W. Kimpel MD





 Official Business Address:



 Department of Psychiatry

 Indiana University School of Medicine

 PR M116

 Institute of Psychiatric Research

 791 Union Drive

 Indianapolis, IN 46202



 Preferred Mailing Address:



 15032 Hunter Court

 Westfield, IN  46074



 (317) 490-5129 Work,  Mobile



 (317) 663-0513 Home (no voice mail please)

 1-(317)-536-2730 FAX


   [[alternative HTML version deleted]]

 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Ramón Díaz-Uriarte
Centro Nacional de Investigaciones Oncológicas (CNIO)
(Spanish National Cancer Center)
Melchor Fernández Almagro, 3
28029 Madrid (Spain)
Fax: +-34-91-224-6972
Phone: +-34-91-224-6900

http://ligarto.org/rdiaz
PGP KeyID: 0xE89B3462
(http://ligarto.org/rdiaz/0xE89B3462.asc)



**NOTA DE CONFIDENCIALIDAD** Este correo electrónico, y en s...{{dropped}}

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] C vs. C++ as learning and development tool for R

2007-01-19 Thread Dirk Eddelbuettel

Mark,

Great question. As Gabor said, if it is just for R, there is no point in
learning C or C++. However, learning new programming paradigms is very useful
in and by itself, and being able to extend R with C, C++ or Fortran is
extremely useful for R.

I would suggest what I jokingly call 'C+' -- use C++, ignore many of the
advanced features for the next little while, and treat it as a 'better
C'.  There is no cost in terms of R extensibility.  Concentrate on the first
third or so of Stroustrup's book as well as others. There are also many
tutorials out there on the net.

Lastly, if it is just for learning other OO paradigms, Python and Ruby are
both excellent, widely used and well documented on the net. I speak neither
very well but have been meaning to learn either or both better for longer
than I'd care to admit in public.

Cheers, Dirk

-- 
Hell, there are no rules here - we're trying to accomplish something. 
  -- Thomas A. Edison

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] C vs. C++ as learning and development tool for R

2007-01-19 Thread Dominick Samperi
Kimpel, Mark William wrote:
 I have 3 years of experience with R and have an interest in becoming a
 better programmer so that I might someday be able to contribute
 packages. Other than R, my only experience was taking Lisp from Daniel
 Friedman in the 1970's. I would like to learn either C or C++ for
 several reasons:

 To gain a better concept of object oriented programming so that I can
 begin to use S4 methods in R.

 To perhaps speed up some things I do repeatedly in R

 To be able to contribute a package someday.
   
If you decide to use C++ with R you should check out the documentation
that comes with the package RcppTemplate, and the sample code that
comes with that package. In my experience C++ (or C or FORTRAN) is
needed for many compute intensive tasks, and the R framework provides
a nice front-end with its extensive collection of visualization and
statistical analysis tools.

Disclaimer: I have no experience with S4.

ds

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] C vs. C++ as learning and development tool for R

2007-01-19 Thread Gabor Grothendieck
On 1/19/07, Dominick Samperi [EMAIL PROTECTED] wrote:
 Kimpel, Mark William wrote:
  I have 3 years of experience with R and have an interest in becoming a
  better programmer so that I might someday be able to contribute
  packages. Other than R, my only experience was taking Lisp from Daniel
  Friedman in the 1970's. I would like to learn either C or C++ for
  several reasons:
 
  To gain a better concept of object oriented programming so that I can
  begin to use S4 methods in R.
 
  To perhaps speed up some things I do repeatedly in R
 
  To be able to contribute a package someday.
 
 If you decide to use C++ with R you should check out the documentation
 that comes with the package RcppTemplate, and the sample code that
 comes with that package. In my experience C++ (or C or FORTRAN) is
 needed for many compute intensive tasks, and the R framework provides
 a nice front-end with its extensive collection of visualization and
 statistical analysis tools.

Actually I have found the opposite. I have never found C/C++ to be necessary.
I have always been able to optimize the R code itself to get it to run
sufficiently fast for my purposes.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] C vs. C++ as learning and development tool for R

2007-01-19 Thread Vladimir Dergachev
On Friday 19 January 2007 1:29 pm, Gabor Grothendieck wrote:
  If you decide to use C++ with R you should check out the documentation
  that comes with the package RcppTemplate, and the sample code that
  comes with that package. In my experience C++ (or C or FORTRAN) is
  needed for many compute intensive tasks, and the R framework provides
  a nice front-end with its extensive collection of visualization and
  statistical analysis tools.

 Actually I have found the opposite. I have never found C/C++ to be
 necessary. I have always been able to optimize the R code itself to get it
 to run sufficiently fast for my purposes.


The nice thing about being able to use C code is that this provides confidence 
that however slowly your R script runs right now you will be able to make it 
faster - no matter what.

On quite a few occasions I have started writing C code and after thinking 
about how I would structure it realized that I can do the same thing in R and 
still get 50% of the speed improvement I get from C.

Also, I am not sure whether this is mentioned anywhere, but I found it to be 
more convenient to use dyn.load directly instead of creating a full-blown R 
package. This way the edit-compile-test cycle is much more convenient.

  best

   Vladimir Dergachev

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] C vs. C++ as learning and development tool for R

2007-01-19 Thread Kimpel, Mark William
Thanks to all for your excellent suggestions. I think will I proceed
working through the Stroustrup book. He has a section on comparing C
with C++ and one on working with legacy C code that may prove helpful. I
also have a C for Dummies (something like that, I don't have it right
next to me) that I have also been reading. A couple of follow-up
questions:

1. As I understand it, if I just wanted to distribute compiled code, I
could use whatever extended C or C++ libraries that I wanted to use,
however, since R is open source and people need to be able to compile
things themselves, I imagine I would get into trouble (figuratively)
using, say, the C++ STL. Would I need to distribute these files as well?
For example, iostream instead of stdio.h. Or, should I just not use
those?

2. For those of you who develop C on Windows (probably a small bunch!),
what is your preferred development environment? I have the free Borland
Turbo C++ and Visual C++ 6.0 (I knew enough to stay away from .NET). I
tried to install the C++ module for Eclipse and, for me at least, it was
a nightmare. I am not UNIX or DOS savvy and setting path variables and
the like just made things too complicated.

3. Lastly, is there a C or C++ community similar to R that I could
address questions relating to those languages to? I don't want to abuse
the R list as I learn.

Thanks,
Mark

Mark W. Kimpel MD 

 

(317) 490-5129 Work,  Mobile

 

(317) 663-0513 Home (no voice mail please)

1-(317)-536-2730 FAX

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] C vs. C++ as learning and development tool for R

2007-01-19 Thread Duncan Murdoch
On 1/19/2007 10:04 AM, Kimpel, Mark William wrote:
 Thanks to all for your excellent suggestions. I think will I proceed
 working through the Stroustrup book. He has a section on comparing C
 with C++ and one on working with legacy C code that may prove helpful. I
 also have a C for Dummies (something like that, I don't have it right
 next to me) that I have also been reading. A couple of follow-up
 questions:
 
 1. As I understand it, if I just wanted to distribute compiled code, I
 could use whatever extended C or C++ libraries that I wanted to use,
 however, since R is open source and people need to be able to compile
 things themselves, I imagine I would get into trouble (figuratively)
 using, say, the C++ STL. Would I need to distribute these files as well?
 For example, iostream instead of stdio.h. Or, should I just not use
 those?

The STL is available on most platforms, as far as I know.  Some more 
specialized libraries (e.g. GSL, database access, OpenGL) are more trouble.

If you want to use the more specialized ones, I'd try compiling your 
package using the standard build tools on one or two platforms, and see 
what happens.
 
 2. For those of you who develop C on Windows (probably a small bunch!),
 what is your preferred development environment? I have the free Borland
 Turbo C++ and Visual C++ 6.0 (I knew enough to stay away from .NET). I
 tried to install the C++ module for Eclipse and, for me at least, it was
 a nightmare. I am not UNIX or DOS savvy and setting path variables and
 the like just made things too complicated.

R uses the MinGW gcc compiler on Windows, so you need to have it 
available to build your packages when you get to that, but it doesn't 
have a nice IDE like those others.  Some purists hate IDEs, but I think 
they are very helpful.  I've never used Turbo C++ and rarely used 
MSVC++, so I can't really recommend one over the other, but I did like 
the Borland IDE for Pascal/Delphi.

Duncan Murdoch

 3. Lastly, is there a C or C++ community similar to R that I could
 address questions relating to those languages to? I don't want to abuse
 the R list as I learn.
 
 Thanks,
 Mark
 
 Mark W. Kimpel MD 
 
  
 
 (317) 490-5129 Work,  Mobile
 
  
 
 (317) 663-0513 Home (no voice mail please)
 
 1-(317)-536-2730 FAX
 
 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] C vs. C++ as learning and development tool for R

2007-01-19 Thread Ross Boylan
On Fri, Jan 19, 2007 at 03:55:30AM -0500, Kimpel, Mark William wrote:
 I have 3 years of experience with R and have an interest in becoming a
 better programmer so that I might someday be able to contribute
 packages. Other than R, my only experience was taking Lisp from Daniel
 Friedman in the 1970's. I would like to learn either C or C++ for
 several reasons:
 
 To gain a better concept of object oriented programming so that I can
 begin to use S4 methods in R.
 
 To perhaps speed up some things I do repeatedly in R
 
 To be able to contribute a package someday.
 
  
 
 I have been doing some reading and from what I can tell R is more
 compatible with C, but C++ has much greater capabilities for OO
 programming.
 
  
 
 I have just started reading The C++ Programming Language: Special
 Edition by Bjarne Stroustrup
 http://search.barnesandnoble.com/booksearch/results.asp?ATH=Bjarne+Stro
 ustrupz=y , he recommends first learning C++ and then then C if
 necessary, but as a developer of C++, he is probably biased.
 
  
 
 I would greatly appreciate the advice of the R developers and package
 contributors on this subject. C or C++?
 

To echo several other comments, if your goal is to work in R, it would
be best to go straight to R.  I haven't used lisp much, but I believe
it is much closer to R than most other languages you could pick.  It
has a functional style, and I recall reading the R's scoping rules
were directly inspired by Scheme, a Lisp variant.  In fact, I didn't
feel I fully grasped them until I looked at Abelson and Sussman's
Structure and Interpretation of Computer Languages (which uses
Scheme).

The functional OO of R is significantly different from the
class-based OO found in most languages calling themselves object
oriented, including C++, Java, Python and smalltalk.  Learning those
other languages to understand R could actually interfere with learning
R.

If and when you need speed, you can program in any language that
supports Fortran or C interfaces, which is almost all of them.

If you're just doing general education

I use C++ in R, and I have to say that programming in C++ is a
wretched experience.  You have to make a major committment to learning
the language, which is a minefield of gotcha's, to use it in full OO
style.  As others on this list and Stroustrup suggest, you can use it
and just incrementally add features over what you would do in C.  It
can also be speedy and powerful (to run, not to program in!), which is
why I'm using it.

For pure OO, I think you can't beat smalltalk, which is freely
available at www.squeak.org (also there is a GNU and several
commerical versions).  The language rules and syntax fit on one page.
The catch is that to use it you need to learn the environment and the
class library; these too are big tasks.

Objective-C is a much more lightweight C'ish OO than C++ (the author
moved smalltalk concepts into C).  It's available as part of the GNU
compilers.  Unlike smalltalk, you might use it if you cared about
performance, and it's the native language of Mac OS-X.  It has a
relatively small learning curve.

Python and Java are other choices for OO, both significantly simpler
than C++.  I find Python to be simple and elegant; it's also nifty for
scripting random tasks.  Java's widely used on the web and in the
enterprise.  Eiffel is also interesting.

I can't say much about libraries already on other machines, but the
C runtime is probably the one you can count on being there the most.

Of course, another route would be to explore other functional
languages, a terrain I barely know: Haskell, ML, OCaml...  In
particular, some of them have lazy evaluation of arguments, which R
also employs.  And there are the functional/object languages like CLOS
(I think the O in OCaml is Object).

Anyway, this risks becoming a general language thread.  My main point,
as someone who's been there, is don't use C++ unless you have a
compelling reason and a lot of time!

Ross Boylan

(Among the languages listed, the ones I've used extensively are C,
C++, Objective-C, Python, R, and smalltalk.)

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] C vs. C++ as learning and development tool for R

2007-01-19 Thread Charles C. Berry
On Sat, 20 Jan 2007, Roger Bivand wrote:

 On Fri, 19 Jan 2007, Kimpel, Mark William wrote:

 Thanks to all for your excellent suggestions. I think will I proceed

[snip]


Commenting on writing R packages with portable C/C++ code:


 [F]ollowing the guides to the letter gets you there like
 marked stones across a marsh. Leaving the path usually gets you at best
 neck deep in the mire, alternatively just bubbles.

Fortune!

[snip]


Charles C. Berry(858) 534-2098
  Dept of Family/Preventive Medicine
E mailto:[EMAIL PROTECTED]   UC San Diego
http://biostat.ucsd.edu/~cberry/ La Jolla, San Diego 92093-0901

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] C vs. C++ as learning and development tool for R

2007-01-19 Thread Vladimir Dergachev
On Friday 19 January 2007 6:46 pm, Ross Boylan wrote:
 On Fri, Jan 19, 2007 at 03:55:30AM -0500, Kimpel, Mark William wrote:
 I can't say much about libraries already on other machines, but the
 C runtime is probably the one you can count on being there the most.

Well, I don't think it is there on Windows machines - and it is specific to 
the compiler. Visual C has several different versions, Borland had its own 
and there were several major releases of GNU C library.

My preference is that on Windows one only distributes static binaries, or, 
uses a small loadable object (i.e. dll) from Tcl/Tk or R.

On Linux I found it is best to link C and X11/GL libraries dynamically (as 
older versions are usually available) and link everything else statically. 
Major exception: condor linked binaries are static.

Caveat - I have not distributed anything but GPL/LGPL code, so making static 
binaries was not an issue. If you have a closed source application than any 
LGPL libraries you use must be linked dynamically and you cannot use GPL code 
at all.

   best

   Vladimir Dergachev

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel