Replace save/load with saveRDS/readRDS to avoid environment side effects#3810
Closed
Thomas-Sedhom wants to merge 4 commits into
Closed
Replace save/load with saveRDS/readRDS to avoid environment side effects#3810Thomas-Sedhom wants to merge 4 commits into
Thomas-Sedhom wants to merge 4 commits into
Conversation
Member
|
@Thomas-Sedhom Thanks for taking this on! You're taking the right direction for what was originally suggested in #3735, but seeing the diff makes me realize there's a backwards compatibility angle that needs some attention. I said more in the issue thread -- Let's discuss there and then come back here to implement once the design is right. |
Member
|
Closing this because of substantial overlap with a bigger refactor @omkarrr2533 is leading. Thanks for the contribution and sorry it went unused! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace save/load with saveRDS/readRDS to avoid environment side effects
Description
The current codebase uses save() and load() for intermediate objects. This approach has several drawbacks:
1- save() requires creating temporary variables to store list elements which is awkward and error prone.
2- load() injects objects by name into the environment and potentially overwriting existing variables silently.
3- Reading specific objects requires extra gymnastics with custom environments.
and the solution is:
All problematic uses of save() and load() have been converted to saveRDS() and readRDS():
1- saveRDS() saves the object directly, without relying on its name.
2- readRDS() explicitly returns the object, which can be assigned to any variable.
This eliminates side effects and makes the code more readable and maintainable.
Motivation and Context
This pattern makes the code harder to maintain and debug.
#3735
Review Time Estimate
Types of changes
Checklist: