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

posts/2023-11-27-objects-loading-namespaces/ #24

Open
utterances-bot opened this issue Nov 27, 2023 · 2 comments
Open

posts/2023-11-27-objects-loading-namespaces/ #24

utterances-bot opened this issue Nov 27, 2023 · 2 comments

Comments

@utterances-bot
Copy link

Mike Mahoney - Helping R find the right methods for unserialized complex objects.

Automatically load package namespaces when reading serialized objects with this One Quick Trick.

https://www.mm218.dev/posts/2023-11-27-objects-loading-namespaces/

Copy link

Interesting! But, actually, I was more intrigued by your \ code. E.g., the first chunk:

bos_rds <- tempfile(fileext = ".rds")
callr::r(
  \(bos_rds) saveRDS(spatialsample::boston_canopy, bos_rds),
  args = list(bos_rds = bos_rds)
) |> 
  invisible()

I've never seen such a difficult way to save an RDS file! :-O Teach me - what is this \(bos_rds) doing? And why calling the whole thing through callr::r?!

@mikemahoney218
Copy link
Owner

mikemahoney218 commented Nov 27, 2023

Ha, sorry! Legacy of the writing process. My first draft here was very intent that I was going to keep the primary R session with as few packages loaded as possible -- so I couldn't call spatialsample::boston_canopy in the primary session, because that would load sf. Then I realized I needed to introduce the problem somehow, and so wind up calling spatialsample::boston_canopy in the primary session ~immediately. I might change this chunk to use the straightforward approach. I immediately changed this (and saving nc_rds) to use the more straightforward approach -- thanks!

(As for "what is \(bos_rds) doing" -- \ is a shorthand for function as of R 4.1, if memory serves, so this defines an in-line function to be run inside the callr R session).

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

No branches or pull requests

3 participants