[R] The end of Matlab
Wacek Kusnierczyk
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Fri Dec 12 14:22:49 CET 2008
Duncan Murdoch wrote:
> On 11/12/2008 9:45 PM, Mike Rowe wrote:
>
>>
>> this.matrix[3:end,end]
>>
>> would be equivalent to:
>>
>> this.matrix[3:nrow(this.matrix),ncol(this.matrix)] # or
>> this.matrix[3:dim(this.matrix)[1],dim(this.matrix)[2]]
>>
>> As you can see, the R version requires more typing, and I am a lousy
>> typist.
>
> It doesn't save typing, but a more readable version would be
>
> rows <- nrow(this.matrix)
> cols <- ncol(this.matrix)
> this.matrix[3:rows, cols]
>
>>
>> With this in mind, I wanted to try to implement something like this in
>> R. It seems like that in order to be able to do this, I would have to
>> be able to access the parse tree of the expression currently being
>> evaluated by the interpreter from within my End function-- is this
>> possible? Since the "[" and "[[" operators are primitive I can't see
>> their arguments via the call stack functions...
>>
>> Anyone got a workaround? Would anybody else like to see this feature
>> added to R?
>
> I like the general rule that subexpressions have values that can be
> evaluated independent of context, so I don't think this is a good idea.
if 'end' poses a problem to the general rule of context-free
establishment of the values of expressions, the python way might be
another option:
x[3:]
instead of
x[3:length(x)]
x[3:end]
(modulo 0-based indexing in python) could this be considered? laziness
seems to be considered a virtue here, and r is stuffed with 'features'
designed by lazy programmers to avoid, e.g., typing quotes; why would
not having to type 'length(...)' or 'nrows(...)' etc. be considered
annoying?
vQ
More information about the R-help
mailing list