Git Product home page Git Product logo

Comments (3)

maurolepore avatar maurolepore commented on August 16, 2024

@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.

from agbfluxes.

ErvanCH avatar ErvanCH commented on August 16, 2024

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.

from agbfluxes.

maurolepore avatar maurolepore commented on August 16, 2024

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.

from agbfluxes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.