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

withr::local_dir() vs withr::defer ... set_wd() #1895

Closed
jonthegeek opened this issue Sep 18, 2023 · 4 comments
Closed

withr::local_dir() vs withr::defer ... set_wd() #1895

jonthegeek opened this issue Sep 18, 2023 · 4 comments

Comments

@jonthegeek
Copy link
Contributor

withr::defer(
{
ui_done("Restoring original working directory: {ui_path(old_wd)}")
setwd(old_wd)
},
envir = env
)
setwd(proj_get())

Does this pre-date withr::local_dir(), or is there a reason it's done more explicitly here? I copied this concept for a package-creating package, without noticing that withr::local_dir() exists and is cleaner.

old_wd <- getwd() # not necessarily same as `old_project`
is also related, in case it's fine to update this to local_dir. I can PR if you'd like.

@jennybc
Copy link
Member

jennybc commented Sep 18, 2023

I think it's that I wanted to schedule that ui_done() to occur at the same time as restoring the working directory.

Developing create_local_thing() was a gradual and somewhat painful process. And, yeah, a lot of ideas and maybe even tools have matured since that got written. So it's believable and that I would write it differently if I started right now. But I plan to leave it alone until/unless there's some other reason to fiddle with it.

@jonthegeek
Copy link
Contributor Author

That makes sense! FWIW, I switched it out in my version, and the tests remained happy, and this also stayed happy:

set_state_inspector(function() {
  list(
    wd = getwd(),
    proj = usethis::proj_get()
  )
})

@jennybc
Copy link
Member

jennybc commented Sep 19, 2023

Nice! So I think local_dir() could be used here, in terms of functionality, but I'm not going to touch this load-bearing helper until there is some other reason to do so.

@jennybc jennybc closed this as completed Sep 19, 2023
@jonthegeek
Copy link
Contributor Author

I really appreciate the modeling of "know when to say no" behavior! Thanks for everything 😊

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

2 participants