[R] writing spdiags function for R

Moreno I. Coco M.I.Coco at sms.ed.ac.uk
Wed Apr 18 19:01:46 CEST 2012


Hi Ben,

>   A couple of quick comments:
>
>  the semicolons at the end of each line are unnecessary (they're
> harmless, but considered bad style -- most common in code of C and
> MATLAB coders

yes, I know, just forgot to clean it up after translating :)

>   You don't need to source("getband.R") inside the body of spdiags,
> probably better to do it outside (so it doesn't get run every time the
> function is called)
>
> if (length(which(bd) == T) != 0)
>
>   can be shortened to
>
>   if (any(bd!=0))
>
>   I haven't looked too carefully but can't all the i/j/d/p stuff be
> replaced by
>
>   n <- nrow(A)
>   p <- 2*n-1
>   d <- seq(-(n-1),(n-1))

yes, all good points, I have acted the changes you suggested,
and it works smooth.

thanks,

Moreno


-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.



More information about the R-help mailing list