[R] SPlus to R

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Wed Oct 5 11:02:52 CEST 2011


On Wed, Oct 5, 2011 at 2:53 AM, Scott Raynaud <scott.raynaud at yahoo.com> wrote:
> I'm trying to convert an S-Plus program to R.  Since I'm a SAS programmer I'm not facile is either S-Plus or R, so I need some help.  All I did was convert the underscores in S-Plus to the assignment operator <-.  Here are the first few lines of the S-Plus file:
>
> sshc _ function(rc, nc, d, method, alpha=0.05, power=0.8,
>              tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5)
> {
> ### for method 1
> if (method==1) {
> ne1 _ ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01)
> return(ne=ne1)
>                }
>
>
> My translation looks like this:
>
> sshc<-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8,
>               tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5)
> {
> ### for method 1
> if (method==1) {
>  ne1<-ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01)
>  return(ne=ne1)
>                }
>
> The program runs without throwing errors, but I'm not getting any ourput in the console.  This is where it should be, right?  I think I have this set up correctly.  I'm using method=3 which only requires nc and d to be specified.  Any ideas why I'm not seeing output?

 Long shot: the code you posted looked like (and hard to tell without
indentation) just a bunch of function definitions. R won't actually do
anything unless you call those functions with some parameters.

 So, when you say you get no output when you 'run' the code, what
exactly do you mean by 'run' the code? What I would do is:

 1. Put the code in a file called 'whatever.R'.
 2. Start R, and do source("whatever.R"). That defines the functions.
do "ls()" and you should see them.
 3. Call one of the functions: sshc(100,10)

I'd call that, in R terms, "calling the sshc function" rather than
running anything.

Barry



More information about the R-help mailing list