Skip to content
This repository has been archived by the owner on Jul 23, 2023. It is now read-only.

Search and address TODO and FIXME #4

Open
maurolepore opened this issue Sep 21, 2018 · 3 comments
Open

Search and address TODO and FIXME #4

maurolepore opened this issue Sep 21, 2018 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@maurolepore
Copy link
Contributor

I flagged a few things with TODO and FIXME that need to be addressed.

@maurolepore maurolepore added the bug Something isn't working label Sep 21, 2018
@maurolepore
Copy link
Contributor Author

maurolepore commented Oct 4, 2018

@ervanSTRI,

I noticed some issues that may make your code run much faster. In three places, the code grows objects instead of pre-allocating an object with the required structure (number of columns, rows, list elements, etc.) and then modifying each element in place. See my comments and let me know if it's unclear.

Generally, you can completely avoid this issue with lapply(). If you still need a for loop, then ensure to create an object with all the elements that will later be replaced (instead of created) inside the for loop.

@ErvanCH
Copy link
Collaborator

ErvanCH commented Oct 5, 2018

Ok. I now see your code and comments. First question: why does the online version differ from the one I have in my package? I've seen the first occurrence you are referring to, but wonder if it saving a lot of time in filling vs cbind-ing a data-frame. I'll give it a try.

@maurolepore
Copy link
Contributor Author

Lines 118, 675, and 845 in AGBfluxes_functions.R.

The source of receiving_df() is here. This is just a slightly different way to do what you were doing before. Notice that the dataframe it creates has only one row, when instead it should have as many rows as the object you will return. Maybe your need expand.grid() or similar.

I would start by fixing the receiving data-structure, and checking if it really improves how fast the code runs. If you achieve better performance, then transforming the code to lapply() (and fridns) won't make it faster -- only more readable. In short, the advantage of lapply() and friends are these:

  • It creates the receiving data-structure internally (so you don't have to do it and you avoid mistakes).
  • It is more readable.

To learn more about the transition from for loops to lapply() and friends see this 12' video: https://youtu.be/GyNqlOjhPCQ

These things are often better shown than explained. But I can't help much until I'm able to run your code and produce an output I can test against. Without that, any change I do may brake something inadvertently. Issue #20 is the priority.

@maurolepore maurolepore added help wanted Extra attention is needed and removed bug Something isn't working labels Oct 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants