Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1:length constructs #55

Closed
bpbond opened this issue Mar 14, 2023 · 1 comment
Closed

1:length constructs #55

bpbond opened this issue Mar 14, 2023 · 1 comment

Comments

@bpbond
Copy link

bpbond commented Mar 14, 2023

I'm looking at the code for layout_as_dynamic and see many loops similar to this:

  for(i in 1:length(gList)){

This is risky in R, because if gList is an empty list, the loop will execute twice!

> for(i in 1:length(list())) print(i)
[1] 1
[1] 0

In general it's safer to use R's seq_along.

Noted as part of openjournals/joss-reviews#5238

@schochastics
Copy link
Owner

This has been on my last far too long, thanks for calling it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants