[R-sig-Debian] littler usage

Dirk Eddelbuettel edd at debian.org
Sat Nov 17 22:47:42 CET 2007


Seb, 

On 17 November 2007 at 15:16, Sebastian P. Luque wrote:
| Hi,
| 
| I've been using r (the little, but sweet one!), and recently found out

It's also way cuter than the ugly Rscript. But heck, I'm one of the parents,
so I had to say that :)

| about the magic argv vector of the rest of arguments passed to it.  How
| can we process an argument that represents elements of a vector:
| 
| $ r littler_ex.R 14 '3, 2'
| Error in ff * ss : non-numeric argument to binary operator
| 
| where:
| 
| ,-----[ cat ~/scripts/R/littler_ex.R ]
| | ff <- as.numeric(argv[1])
| | ss <- c(argv[2])
| | print(ff * ss)
| `-----

You're almost there -- just use 'as.numeric' on ss too:

edd at ron:~> cat /tmp/seb.r
#!/usr/bin/env r

ff <- as.numeric(argv[1])
ss <- as.numeric(argv[2])
print(ff * ss)
edd at ron:~> /tmp/seb.r 2 3
[1] 6
edd at ron:~>    

There are a few examples of argv use in the examples directory:

edd at ron:~> grep -c argv /usr/share/doc/littler/examples/*r
/usr/share/doc/littler/examples/fsizes.r:0
/usr/share/doc/littler/examples/install.r:2
/usr/share/doc/littler/examples/mph.r:2
/usr/share/doc/littler/examples/pace.r:3
/usr/share/doc/littler/examples/update.r:0

Hope this helps,  Dirk

-- 
Three out of two people have difficulties with fractions.



More information about the R-SIG-Debian mailing list