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

Simplified and Extended "Updating by Reference" Section in Joins Vignette #6847

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

venom1204
Copy link
Contributor

@venom1204 venom1204 commented Mar 3, 2025

Simplified and extended the Updating by Reference section in the Joins in data.table vignette.
closes #6846
in this i

  • Added a simpler one-to-one update example for clarity.
  • Provided an efficient solution for updating multiple columns using mget(cols), reducing unnecessary copies.
  • Clarified RIGHT JOIN limitations and how := modifies x in place but does not update i.
  • Mentioned performance improvements observed in large datasets.

@jangorecki can you please review this when you have time and suggest me if any changes are needed
thank you

Copy link

codecov bot commented Mar 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.59%. Comparing base (6aa99f5) to head (5a3f19c).
Report is 17 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6847   +/-   ##
=======================================
  Coverage   98.59%   98.59%           
=======================================
  Files          79       79           
  Lines       14661    14665    +4     
=======================================
+ Hits        14455    14459    +4     
  Misses        206      206           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jangorecki
Copy link
Member

I think it is best to ping author of this vignette. I haven't had yet opportunity to read the original version.

- The on = .(id = product_id) ensures that updates happen based on matching IDs.
- This method modifies Products in place, avoiding unnecessary copies.

2) If we need to get the latest price and date (instead of all matches), we can still use := efficiently:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we've cleanly explained the difference between this join and the previous one. The only difference I see is tail() vs. last(), am I missing something?

IIUC the difference between tail() and last() would be that last() can skip NA values, right?

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
- We add a new `last_updated` column to track when the price was last changed.
- The `by = .EACHI` ensures that the `tail` function is applied for each product in `ProductPriceHistory`.
#### Let's update our `Products` table with the latest price from `ProductPriceHistory`:
```{r Simple One-to-One Update}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these valid {knitr} chunk names? regardless, please use machine-readable names (a la https://style.tidyverse.org/files.html)

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@venom1204 venom1204 requested a review from MichaelChirico March 7, 2025 08:39

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@venom1204
Copy link
Contributor Author

@lucasmation @MichaelChirico
I've refined and modified the section to align with the issue requirements. Kindly review and share any suggestions when you have time.

thanks.

@Advaitgaur004
Copy link

Advaitgaur004 commented Mar 18, 2025

@venom1204, what is the update on this, have you tested the code .

data.table::last(c(1, NA))
# [1] NA

data.table::data.table(a = c(1, 1, 2, 2), b = c(1, NA, 2, NA))[, last(b), by=a]
#        a    V1
#    <num> <num>
# 1:     1    NA
# 2:     2    NA

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@venom1204
Copy link
Contributor Author

@MichaelChirico I’ve minimized the changes I introduced while ensuring they contain sufficient information and remain easy to understand. Could you review them and let me know if any further simplification is needed, or if they are good as they are?

@venom1204
Copy link
Contributor Author

@iagogv3 I’ve incorporated your suggestions into my latest version. Could you review the updates and let me know if any further improvements are needed? Your feedback would be greatly appreciated!
thank you.

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

Successfully merging this pull request may close these issues.

Joins in data.table vignette. Simplify and extend the "update by reference section"
4 participants