laresbernardo / lares

Analytics & Machine Learning R Sidekick
https://laresbernardo.github.io/lares/
233 stars 49 forks source link

robyn_performance Error in if (totals) ret <- rbind(ret, totals_base, grand_total) : the condition has length > 1 #54

Closed louisjanin closed 4 months ago

louisjanin commented 4 months ago

Hi there,

I just tried to use your robyn_performance function and had 2 issues actually. The weirdest is I couldn't run it without manully declaring it (copy / paste the function code into my terminal). Not sure why... Second is I got an error at this line : Error in if (totals) ret <- rbind(ret, totals_base, grand_total) : the condition has length > 1

I could fix it with this : if (nrow(totals)) ret <- rbind(ret, totals_base, grand_total)

Maybe it's just me, or I missed some imports, just wanted to let you know :)

laresbernardo commented 4 months ago

Ha, good catch. Just included the totals parameter in case the user doesn't need the totals but only each channels results and didn't test it (sorry). The other one is an easy fix too.. Will post a fix it and will ping you. thanks for testing and reporting @louisjanin

laresbernardo commented 4 months ago

Can you please update (lares::updateLares()), refresh your R session, and check for both issues? Thanks a lot.

louisjanin commented 4 months ago

Perfect thanks! May I suggest an option in this function to return results per each date ? That is having a full contribution report per week (when the input dataset is weekly). So that it would be so easy to then plot contrib over dates?

laresbernardo commented 4 months ago

For that, you already have Robyn's decomp_plot() :) You can extract the dataframe from there.

On the issues, are they resolved?

louisjanin commented 4 months ago

awesome! I didn't this one! Yes, issues are resolved, thanks again!

laresbernardo commented 4 months ago

May I suggest an option in this function to return results per each date

Try this and customize it whoever you see fit:

dates <- unique(OutputCollect$mediaVecCollect$ds)
res <- lapply(dates, function(x) {
  lares::robyn_performance(
    InputCollect, OutputCollect,
    start_date = x,
    end_date = x)
})
df <- dplyr::bind_rows(res)