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

add on.exit() after setwd() in java_quick_install and java_download #54

Open
e-kotov opened this issue Mar 3, 2025 · 0 comments
Open
Labels
good first issue Good for newcomers help wanted Extra attention is needed ro-hackathon-2025

Comments

@e-kotov
Copy link
Owner

e-kotov commented Mar 3, 2025

There is some code that is mainly intended for testing and running examples.

if (temp_dir) {
temp_dir <- tempdir()
setwd(temp_dir)
if (!dir.exists("rJavaEnv_cache")) {
dir.create("rJavaEnv_cache", recursive = TRUE)
}
cache_path <- file.path(temp_dir, "rJavaEnv_cache")
if (!dir.exists("rJavaEnv_project")) {
dir.create("rJavaEnv_project", recursive = TRUE)
}
project_path <- file.path(temp_dir, "rJavaEnv_project")
} else {
cache_path <- getOption("rJavaEnv.cache_path")
}

and

# override cache_path if temp_dir is set to TRUE
if (temp_dir) {
temp_dir <- tempdir()
setwd(temp_dir)
if (!dir.exists("rJavaEnv_cache")) {
dir.create("rJavaEnv_cache", recursive = TRUE)
}
cache_path <- file.path(temp_dir, "rJavaEnv_cache")
}

After running goodpractice::gp("rJavaEnv") I got a suggestion:

✖ avoid calling setwd(), it changes the global environment. If you need it, consider using on.exit() to restore the
    working directory.

    R/java_download.R:36:5
    R/java_quick_install.R:28:5
    vignettes/rJavaEnv-step-by-step.qmd:27:1
    vignettes/rJavaEnv.qmd:48:1

So even though this code is not critical for the functioning of the package, it would indeed be nice to stick to the good practices and add the appropriate on.exit() call to restore the working directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed ro-hackathon-2025
Projects
None yet
Development

No branches or pull requests

1 participant