hydromad icon indicating copy to clipboard operation
hydromad copied to clipboard

Avoid 1:ncol(...) expressions, use seq_len

Open josephguillaume opened this issue 4 years ago • 3 comments

Lintr warning:

##[warning]Avoid 1:ncol(...) expressions, use seq_len.

josephguillaume avatar Jul 01 '20 01:07 josephguillaume

##[warning]Avoid 1:NCOL(...) expressions, use seq_len. ##[warning]Avoid 1:NROW(...) expressions, use seq_len. ##[warning]Avoid 1:length(...) expressions, use seq_len. ##[warning]Avoid 1:nrow(...) expressions, use seq_len.

josephguillaume avatar Jul 01 '20 01:07 josephguillaume

Can we discuss this a bit. If the object (...) is a matrix, we would have to do: seq_len(...[,1])?? Or use dim()? What do you suggest. I guess they don't like 1:..?

Mentioning this as there are a few I come across in my editing Can fix them on the go

WillemVervoort avatar Jul 01 '20 05:07 WillemVervoort

There's seq_along(along.with) and seq_len(length.out). The first just uses the length of the object. The behaviour is unclear for matrices, so it's better to do seq_len(NROW(object)) for instance.

These shouldn't be too hard to find-and-replace, so it's up to you whether it's easy enough to do them while you're working on other things.

josephguillaume avatar Jul 01 '20 05:07 josephguillaume