├── .Rbuildignore ├── .editorconfig ├── .github ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md └── workflows │ ├── R-CMD-check-HTML5.yaml │ ├── R-CMD-check.yaml │ ├── pkgcheck.yaml │ ├── pkgdown.yaml │ ├── render-README.yaml │ ├── rhub.yaml │ ├── test-coverage.yaml │ └── update-citation-cff.yaml ├── .gitignore ├── CITATION.cff ├── DESCRIPTION ├── LICENSE ├── LICENSE.md ├── NAMESPACE ├── NEWS.md ├── R ├── consent.R ├── global_params.R ├── internal_utilities.R ├── java_download.R ├── java_env.R ├── java_install.R ├── java_manage.R ├── java_manage_distrib_cache.R ├── java_manage_installed_cache.R ├── java_manage_project.R ├── java_quick_install.R ├── java_unpack.R ├── java_valid_versions.R ├── onLoad.R ├── rJavaEnv-package.R └── use_java.R ├── README.md ├── README.qmd ├── _pkgdown.yml ├── codemeta.json ├── cran-comments.md ├── inst ├── CITATION ├── extdata │ └── java_urls.json ├── resources │ └── consent-info └── schemaorg.json ├── man ├── figures │ ├── card.png │ └── logo.png ├── global_quiet_param.Rd ├── java_check_version_cmd.Rd ├── java_check_version_rjava.Rd ├── java_check_version_system.Rd ├── java_clear.Rd ├── java_clear_distrib_cache.Rd ├── java_clear_in_project.Rd ├── java_clear_installed_cache.Rd ├── java_download.Rd ├── java_env_set.Rd ├── java_env_set_rprofile.Rd ├── java_env_set_session.Rd ├── java_env_unset.Rd ├── java_install.Rd ├── java_list.Rd ├── java_list_distrib_cache.Rd ├── java_list_in_project.Rd ├── java_list_installed_cache.Rd ├── java_quick_install.Rd ├── java_unpack.Rd ├── java_urls_load.Rd ├── java_valid_major_versions_corretto.Rd ├── java_valid_versions.Rd ├── java_version_check_rscript.Rd ├── platform_detect.Rd ├── rJavaEnv-package.Rd ├── rje_consent.Rd ├── rje_consent_check.Rd ├── rje_envvar_exists.Rd ├── urls_test_all.Rd └── use_java.Rd ├── pkgdown ├── assets │ └── images │ │ └── card.png └── favicon │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ ├── apple-touch-icon-180x180.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ ├── favicon-96x96.png │ ├── favicon.ico │ ├── favicon.svg │ ├── site.webmanifest │ ├── web-app-manifest-192x192.png │ └── web-app-manifest-512x512.png ├── rJavaEnv.Rproj ├── tests ├── testthat.R └── testthat │ ├── test-java_unpack.R │ └── test-java_valid_versions.R ├── tools └── meta-data-update-and-submission.R └── vignettes ├── .gitignore ├── bibliography.bib ├── data-for-vignettes ├── data_table_dlstats.csv ├── get-data-for-vignettes.R ├── ggplot2_dlstats.csv ├── produce-graphs-for-why-rJavaEnv.R ├── rJava_dependants_dlstats.csv ├── rJava_dependants_dlstats_bioc.csv ├── rJava_dependants_dlstats_cran.csv └── rJava_dlstats.csv ├── media └── images │ ├── rJavaDepIndivAll.svg │ ├── rJavaDepIndivFiltered.svg │ ├── rJavaDepIndivFilteredXslx.svg │ └── rJavaPopularity.svg ├── multiple-java-with-targets-callr.qmd ├── rJavaEnv-step-by-step.qmd ├── rJavaEnv.qmd └── why-rJavaEnv.qmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^rJavaEnv\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^LICENSE\.md$ 4 | ^README\.Rmd$ 5 | ^README\.qmd$ 6 | ^cran-comments\.md$ 7 | ^_pkgdown\.yml$ 8 | ^docs$ 9 | ^pkgdown$ 10 | ^\.github$ 11 | ^\.Rprofile$ 12 | ^rjavaenv$ 13 | ^private$ 14 | ^codemeta\.json$ 15 | ^CITATION\.cff$ 16 | ^doc$ 17 | ^Meta$ 18 | ^CODE_OF_CONDUCT\.md$ 19 | ^vignettes/why-rJavaEnv\.qmd$ 20 | ^vignettes/data-for-vignettes$ 21 | ^vignettes/bibliography.bib$ 22 | ^vignettes/media$ 23 | ^CRAN-SUBMISSION$ 24 | ^vignettes/.quarto$ 25 | ^revdep$ 26 | ^man/figures/card.png$ 27 | ^tools$ 28 | ^\.editorconfig$ 29 | ^revdep$ 30 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | indent_style = space 8 | 9 | [*.{r,R,rmd,Rmd,qmd}] 10 | indent_size = 2 11 | trim_trailing_whitespace = true 12 | 13 | [*.{cpp,h,hpp}] 14 | indent_size = 2 15 | trim_trailing_whitespace = true 16 | 17 | [Makefile] 18 | indent_style = tab -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, caste, color, religion, or sexual 10 | identity and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the overall 26 | community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or advances of 31 | any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email address, 35 | without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at kotov.egor@gmail.com. 63 | All complaints will be reviewed and investigated promptly and fairly. 64 | 65 | All community leaders are obligated to respect the privacy and security of the 66 | reporter of any incident. 67 | 68 | ## Enforcement Guidelines 69 | 70 | Community leaders will follow these Community Impact Guidelines in determining 71 | the consequences for any action they deem in violation of this Code of Conduct: 72 | 73 | ### 1. Correction 74 | 75 | **Community Impact**: Use of inappropriate language or other behavior deemed 76 | unprofessional or unwelcome in the community. 77 | 78 | **Consequence**: A private, written warning from community leaders, providing 79 | clarity around the nature of the violation and an explanation of why the 80 | behavior was inappropriate. A public apology may be requested. 81 | 82 | ### 2. Warning 83 | 84 | **Community Impact**: A violation through a single incident or series of 85 | actions. 86 | 87 | **Consequence**: A warning with consequences for continued behavior. No 88 | interaction with the people involved, including unsolicited interaction with 89 | those enforcing the Code of Conduct, for a specified period of time. This 90 | includes avoiding interactions in community spaces as well as external channels 91 | like social media. Violating these terms may lead to a temporary or permanent 92 | ban. 93 | 94 | ### 3. Temporary Ban 95 | 96 | **Community Impact**: A serious violation of community standards, including 97 | sustained inappropriate behavior. 98 | 99 | **Consequence**: A temporary ban from any sort of interaction or public 100 | communication with the community for a specified period of time. No public or 101 | private interaction with the people involved, including unsolicited interaction 102 | with those enforcing the Code of Conduct, is allowed during this period. 103 | Violating these terms may lead to a permanent ban. 104 | 105 | ### 4. Permanent Ban 106 | 107 | **Community Impact**: Demonstrating a pattern of violation of community 108 | standards, including sustained inappropriate behavior, harassment of an 109 | individual, or aggression toward or disparagement of classes of individuals. 110 | 111 | **Consequence**: A permanent ban from any sort of public interaction within the 112 | community. 113 | 114 | ## Attribution 115 | 116 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 117 | version 2.1, available at 118 | . 119 | 120 | Community Impact Guidelines were inspired by 121 | [Mozilla's code of conduct enforcement ladder][https://github.com/mozilla/inclusion]. 122 | 123 | For answers to common questions about this code of conduct, see the FAQ at 124 | . Translations are available at . 125 | 126 | [homepage]: https://www.contributor-covenant.org 127 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to rJavaEnv 2 | 3 | This outlines how to propose a change to rJavaEnv. 4 | For a detailed discussion on contributing to this and other tidyverse packages, please see the [development contributing guide](https://rstd.io/tidy-contrib) and [code review principles](https://code-review.tidyverse.org/). 5 | 6 | ## Fixing typos 7 | 8 | You can fix typos, spelling mistakes, or grammatical errors in the documentation directly using the GitHub web interface, as long as the changes are made in the _source_ file. 9 | This generally means you'll need to edit [roxygen2 comments](https://roxygen2.r-lib.org/articles/roxygen2.html) in an `.R`, not a `.Rd` file. 10 | You can find the `.R` file that generates the `.Rd` by reading the comment in the first line. 11 | 12 | ## Bigger changes 13 | 14 | If you want to make a bigger change, it's a good idea to first file an issue and make sure someone from the team agrees that it’s needed. 15 | If you’ve found a bug, please file an issue that illustrates the bug with a minimal 16 | [reprex](https://www.tidyverse.org/help/#reprex) (this will also help you write a unit test, if needed). 17 | See the guide on [how to create a great issue](https://code-review.tidyverse.org/issues/) for more advice. 18 | 19 | ### Pull request process 20 | 21 | * Fork the package and clone onto your computer. If you haven't done this before, we recommend using `usethis::create_from_github("e-kotov/rJavaEnv", fork = TRUE)`. 22 | 23 | * Install all development dependencies with `devtools::install_dev_deps()`, and then make sure the package passes R CMD check by running `devtools::check()`. 24 | If R CMD check doesn't pass cleanly, it's a good idea to ask for help before continuing. 25 | * Create a Git branch for your pull request (PR). We recommend using `usethis::pr_init("brief-description-of-change")`. 26 | 27 | * Make your changes, commit to git, and then create a PR by running `usethis::pr_push()`, and following the prompts in your browser. 28 | The title of your PR should briefly describe the change. 29 | The body of your PR should contain `Fixes #issue-number`. 30 | 31 | * For user-facing changes, add a bullet to the top of `NEWS.md` (i.e. just below the first header). Follow the style described in . 32 | 33 | ### Code style 34 | 35 | * New code should follow the tidyverse [style guide](https://style.tidyverse.org). 36 | You can use the [styler](https://CRAN.R-project.org/package=styler) package to apply these styles, but please don't restyle code that has nothing to do with your PR. 37 | 38 | * We use [roxygen2](https://cran.r-project.org/package=roxygen2), with [Markdown syntax](https://cran.r-project.org/web/packages/roxygen2/vignettes/rd-formatting.html), for documentation. 39 | 40 | * We use [testthat](https://cran.r-project.org/package=testthat) for unit tests. 41 | Contributions with test cases included are easier to accept. 42 | 43 | ## Code of Conduct 44 | 45 | Please note that the rJavaEnv project is released with a 46 | [Contributor Code of Conduct](.github/CODE_OF_CONDUCT.md). By contributing to this 47 | project you agree to abide by its terms. 48 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check-HTML5.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: R-CMD-check-HTML5 10 | 11 | jobs: 12 | R-CMD-check: 13 | runs-on: ubuntu-latest 14 | env: 15 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 16 | R_KEEP_PKG_SOURCE: yes 17 | _R_CHECK_RD_VALIDATE_RD2HTML_: TRUE 18 | steps: 19 | - uses: actions/checkout@v2 20 | 21 | - name: Install pdflatex 22 | run: sudo apt-get install texlive-latex-base texlive-fonts-recommended texlive-fonts-extra texlive-latex-extra 23 | 24 | - name: Install tidy 25 | run: sudo apt install tidy 26 | 27 | - uses: r-lib/actions/setup-r@v2 28 | with: 29 | r-version: 'devel' 30 | http-user-agent: 'release' 31 | use-public-rspm: true 32 | 33 | - uses: r-lib/actions/setup-r-dependencies@v2 34 | with: 35 | extra-packages: any::rcmdcheck 36 | needs: check 37 | 38 | - uses: r-lib/actions/check-r-package@v2 39 | with: 40 | args: '"--as-cran"' 41 | build_args: 'character()' 42 | error-on: '"note"' 43 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | branches: [main] 8 | 9 | name: R-CMD-check 10 | 11 | permissions: read-all 12 | 13 | jobs: 14 | R-CMD-check: 15 | runs-on: ${{ matrix.config.os }} 16 | 17 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 18 | 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | config: 23 | - {os: macos-latest, r: 'release'} 24 | - {os: windows-latest, r: 'release'} 25 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 26 | - {os: ubuntu-latest, r: 'release'} 27 | - {os: ubuntu-latest, r: 'oldrel-1'} 28 | 29 | env: 30 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 31 | R_KEEP_PKG_SOURCE: yes 32 | 33 | steps: 34 | - uses: actions/checkout@v4 35 | 36 | - uses: r-lib/actions/setup-pandoc@v2 37 | 38 | - uses: r-lib/actions/setup-r@v2 39 | with: 40 | r-version: ${{ matrix.config.r }} 41 | http-user-agent: ${{ matrix.config.http-user-agent }} 42 | use-public-rspm: true 43 | 44 | - uses: r-lib/actions/setup-r-dependencies@v2 45 | with: 46 | extra-packages: any::rcmdcheck 47 | needs: check 48 | 49 | - uses: r-lib/actions/check-r-package@v2 50 | with: 51 | upload-snapshots: true 52 | build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' 53 | -------------------------------------------------------------------------------- /.github/workflows/pkgcheck.yaml: -------------------------------------------------------------------------------- 1 | name: pkgcheck 2 | 3 | # This will cancel running jobs once a new run is triggered 4 | concurrency: 5 | group: ${{ github.workflow }}-${{ github.head_ref }} 6 | cancel-in-progress: true 7 | 8 | on: 9 | # Manually trigger the Action under Actions/pkgcheck 10 | workflow_dispatch: 11 | # Run on every push to main 12 | push: 13 | branches: 14 | - main 15 | pull_request: 16 | branches: 17 | - main 18 | 19 | jobs: 20 | pkgcheck: 21 | runs-on: ubuntu-latest 22 | permissions: 23 | issues: write 24 | steps: 25 | - uses: ropensci-review-tools/pkgcheck-action@main 26 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | release: 9 | types: [published] 10 | workflow_dispatch: 11 | 12 | name: pkgdown 13 | 14 | permissions: read-all 15 | 16 | jobs: 17 | pkgdown: 18 | runs-on: ubuntu-latest 19 | # Only restrict concurrency for non-PR jobs 20 | concurrency: 21 | group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} 22 | env: 23 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 24 | permissions: 25 | contents: write 26 | steps: 27 | - uses: actions/checkout@v4 28 | 29 | - uses: r-lib/actions/setup-pandoc@v2 30 | 31 | - uses: r-lib/actions/setup-r@v2 32 | with: 33 | use-public-rspm: true 34 | 35 | - uses: r-lib/actions/setup-r-dependencies@v2 36 | with: 37 | extra-packages: any::pkgdown, any::bookdown, local::. 38 | needs: website 39 | 40 | - name: Build site 41 | run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) 42 | shell: Rscript {0} 43 | 44 | - name: Deploy to GitHub pages 🚀 45 | if: github.event_name != 'pull_request' 46 | uses: JamesIves/github-pages-deploy-action@v4.5.0 47 | with: 48 | clean: false 49 | branch: gh-pages 50 | folder: docs 51 | -------------------------------------------------------------------------------- /.github/workflows/render-README.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/master/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | paths: ['README.Rmd'] 6 | workflow_dispatch: 7 | paths: ['README.Rmd'] 8 | 9 | 10 | name: Render README 11 | 12 | jobs: 13 | render-rmarkdown: 14 | runs-on: ubuntu-latest 15 | env: 16 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 17 | steps: 18 | - name: Checkout repo 19 | uses: actions/checkout@v3 20 | with: 21 | fetch-depth: 0 22 | 23 | - uses: r-lib/actions/setup-pandoc@v2 24 | 25 | - uses: r-lib/actions/setup-r@v2 26 | 27 | - name: install rmarkdown from PPM 28 | run: Rscript -e 'install.packages("rmarkdown", repos=c("https://packagemanager.rstudio.com/cran/__linux__/jammy/latest"))' 29 | 30 | - name: Install devtools and the target package 31 | run: | 32 | Rscript -e 'install.packages("rJavaEnv", repos=c("https://community.r-multiverse.org", "https://packagemanager.posit.co/cran/__linux__/jammy/latest"))' 33 | 34 | 35 | - name: Render README.Rmd 36 | run: | 37 | Rscript -e 'rmarkdown::render("README.Rmd")' 38 | 39 | - name: Commit results 40 | run: | 41 | git config --local user.name "github-actions[bot]" 42 | git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" 43 | git add README.md 44 | git commit -m 'Re-build README.Rmd' || echo "No changes to commit" 45 | git push origin || echo "No changes to commit" 46 | -------------------------------------------------------------------------------- /.github/workflows/rhub.yaml: -------------------------------------------------------------------------------- 1 | # R-hub's generic GitHub Actions workflow file. It's canonical location is at 2 | # https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml 3 | # You can update this file to a newer version using the rhub2 package: 4 | # 5 | # rhub::rhub_setup() 6 | # 7 | # It is unlikely that you need to modify this file manually. 8 | 9 | name: R-hub 10 | run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}" 11 | 12 | on: 13 | workflow_dispatch: 14 | inputs: 15 | config: 16 | description: 'A comma separated list of R-hub platforms to use.' 17 | type: string 18 | default: 'linux,windows,macos' 19 | name: 20 | description: 'Run name. You can leave this empty now.' 21 | type: string 22 | id: 23 | description: 'Unique ID. You can leave this empty now.' 24 | type: string 25 | 26 | jobs: 27 | 28 | setup: 29 | runs-on: ubuntu-latest 30 | outputs: 31 | containers: ${{ steps.rhub-setup.outputs.containers }} 32 | platforms: ${{ steps.rhub-setup.outputs.platforms }} 33 | 34 | steps: 35 | # NO NEED TO CHECKOUT HERE 36 | - uses: r-hub/actions/setup@v1 37 | with: 38 | config: ${{ github.event.inputs.config }} 39 | id: rhub-setup 40 | 41 | linux-containers: 42 | needs: setup 43 | if: ${{ needs.setup.outputs.containers != '[]' }} 44 | runs-on: ubuntu-latest 45 | name: ${{ matrix.config.label }} 46 | strategy: 47 | fail-fast: false 48 | matrix: 49 | config: ${{ fromJson(needs.setup.outputs.containers) }} 50 | container: 51 | image: ${{ matrix.config.container }} 52 | 53 | steps: 54 | - uses: r-hub/actions/checkout@v1 55 | - uses: r-hub/actions/platform-info@v1 56 | with: 57 | token: ${{ secrets.RHUB_TOKEN }} 58 | job-config: ${{ matrix.config.job-config }} 59 | - uses: r-hub/actions/setup-deps@v1 60 | with: 61 | token: ${{ secrets.RHUB_TOKEN }} 62 | job-config: ${{ matrix.config.job-config }} 63 | - uses: r-hub/actions/run-check@v1 64 | with: 65 | token: ${{ secrets.RHUB_TOKEN }} 66 | job-config: ${{ matrix.config.job-config }} 67 | 68 | other-platforms: 69 | needs: setup 70 | if: ${{ needs.setup.outputs.platforms != '[]' }} 71 | runs-on: ${{ matrix.config.os }} 72 | name: ${{ matrix.config.label }} 73 | strategy: 74 | fail-fast: false 75 | matrix: 76 | config: ${{ fromJson(needs.setup.outputs.platforms) }} 77 | 78 | steps: 79 | - uses: r-hub/actions/checkout@v1 80 | - uses: r-hub/actions/setup-r@v1 81 | with: 82 | job-config: ${{ matrix.config.job-config }} 83 | token: ${{ secrets.RHUB_TOKEN }} 84 | - uses: r-hub/actions/platform-info@v1 85 | with: 86 | token: ${{ secrets.RHUB_TOKEN }} 87 | job-config: ${{ matrix.config.job-config }} 88 | - uses: r-hub/actions/setup-deps@v1 89 | with: 90 | job-config: ${{ matrix.config.job-config }} 91 | token: ${{ secrets.RHUB_TOKEN }} 92 | - uses: r-hub/actions/run-check@v1 93 | with: 94 | job-config: ${{ matrix.config.job-config }} 95 | token: ${{ secrets.RHUB_TOKEN }} 96 | -------------------------------------------------------------------------------- /.github/workflows/test-coverage.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: test-coverage 10 | 11 | permissions: read-all 12 | 13 | jobs: 14 | test-coverage: 15 | runs-on: ubuntu-latest 16 | env: 17 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 18 | 19 | steps: 20 | - uses: actions/checkout@v4 21 | 22 | - uses: r-lib/actions/setup-r@v2 23 | with: 24 | use-public-rspm: true 25 | 26 | - uses: r-lib/actions/setup-r-dependencies@v2 27 | with: 28 | extra-packages: any::covr, any::xml2 29 | needs: coverage 30 | 31 | - name: Test coverage 32 | run: | 33 | cov <- covr::package_coverage( 34 | quiet = FALSE, 35 | clean = FALSE, 36 | install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") 37 | ) 38 | covr::to_cobertura(cov) 39 | shell: Rscript {0} 40 | 41 | - uses: codecov/codecov-action@v4 42 | with: 43 | fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }} 44 | file: ./cobertura.xml 45 | plugin: noop 46 | disable_search: true 47 | token: ${{ secrets.CODECOV_TOKEN }} 48 | 49 | - name: Show testthat output 50 | if: always() 51 | run: | 52 | ## -------------------------------------------------------------------- 53 | find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true 54 | shell: bash 55 | 56 | - name: Upload test results 57 | if: failure() 58 | uses: actions/upload-artifact@v4 59 | with: 60 | name: coverage-test-failures 61 | path: ${{ runner.temp }}/package 62 | -------------------------------------------------------------------------------- /.github/workflows/update-citation-cff.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/master/examples 2 | # The action runs when: 3 | # - A new release is published 4 | # - The DESCRIPTION or inst/CITATION are modified 5 | # - Can be run manually 6 | # For customizing the triggers, visit https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows 7 | on: 8 | release: 9 | types: [published] 10 | push: 11 | branches: [master, main] 12 | paths: 13 | - DESCRIPTION 14 | - inst/CITATION 15 | workflow_dispatch: 16 | 17 | name: Update CITATION.cff 18 | 19 | jobs: 20 | update-citation-cff: 21 | runs-on: macos-latest 22 | env: 23 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 24 | steps: 25 | - uses: actions/checkout@v3 26 | - uses: r-lib/actions/setup-r@v2 27 | - uses: r-lib/actions/setup-r-dependencies@v2 28 | with: 29 | extra-packages: | 30 | any::cffr 31 | any::V8 32 | 33 | - name: Update CITATION.cff 34 | run: | 35 | 36 | library(cffr) 37 | 38 | # Customize with your own code 39 | # See https://docs.ropensci.org/cffr/articles/cffr.html 40 | 41 | # Write your own keys 42 | mykeys <- list() 43 | 44 | # Create your CITATION.cff file 45 | cff_write(keys = mykeys) 46 | 47 | shell: Rscript {0} 48 | 49 | - name: Commit results 50 | run: | 51 | git config --local user.name "github-actions[bot]" 52 | git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" 53 | git add CITATION.cff 54 | git commit -m 'Update CITATION.cff' || echo "No changes to commit" 55 | git push origin || echo "No changes to commit" 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .Rdata 4 | .httr-oauth 5 | .DS_Store 6 | .quarto 7 | docs 8 | bin 9 | private 10 | README_cache 11 | renv 12 | .Rprofile 13 | rjavaenv 14 | /doc/ 15 | /Meta/ 16 | 17 | /.quarto/ 18 | revdep 19 | -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | # -------------------------------------------- 2 | # CITATION file created with {cffr} R package 3 | # See also: https://docs.ropensci.org/cffr/ 4 | # -------------------------------------------- 5 | 6 | cff-version: 1.2.0 7 | message: 'To cite package "rJavaEnv" in publications use:' 8 | type: software 9 | license: MIT 10 | title: 'rJavaEnv: ''Java'' Environments for R Projects' 11 | version: 0.3.0 12 | doi: 10.32614/CRAN.package.rJavaEnv 13 | identifiers: 14 | - type: doi 15 | value: 10.32614/CRAN.package.rJavaEnv 16 | abstract: 'Quickly install ''Java Development Kit (JDK)'' without administrative privileges 17 | and set environment variables in current R session or project to solve common issues 18 | with ''Java'' environment management in ''R''. Recommended to users of ''Java''/''rJava''-dependent 19 | ''R'' packages such as ''r5r'', ''opentripplanner'', ''xlsx'', ''openNLP'', ''rWeka'', 20 | ''RJDBC'', ''tabulapdf'', and many more. ''rJavaEnv'' prevents common problems like 21 | ''Java'' not found, ''Java'' version conflicts, missing ''Java'' installations, 22 | and the inability to install ''Java'' due to lack of administrative privileges. 23 | ''rJavaEnv'' automates the download, installation, and setup of the ''Java'' on 24 | a per-project basis by setting the relevant ''JAVA_HOME'' in the current ''R'' session 25 | or the current working directory (via ''.Rprofile'', with the user''s consent). 26 | Similar to what ''renv'' does for ''R'' packages, ''rJavaEnv'' allows different 27 | ''Java'' versions to be used across different projects, but can also be configured 28 | to allow multiple versions within the same project (e.g. with the help of ''targets'' 29 | package). Note: there are a few extra steps for ''Linux'' users, who don''t have 30 | any ''Java'' previously installed in their system, and who prefer package installation 31 | from source, rather then installing binaries from ''Posit Package Manager''. See 32 | documentation for details.' 33 | authors: 34 | - family-names: Kotov 35 | given-names: Egor 36 | email: kotov.egor@gmail.com 37 | orcid: https://orcid.org/0000-0001-6690-5345 38 | - family-names: Chan 39 | given-names: Chung-hong 40 | email: chainsawtiney@gmail.com 41 | orcid: https://orcid.org/0000-0002-6232-7530 42 | preferred-citation: 43 | type: manual 44 | title: 'rJavaEnv: Java Environments for R Projects' 45 | authors: 46 | - family-names: Kotov 47 | given-names: Egor 48 | email: kotov.egor@gmail.com 49 | orcid: https://orcid.org/0000-0001-6690-5345 50 | - family-names: Chan 51 | given-names: Chung-hong 52 | email: chainsawtiney@gmail.com 53 | orcid: https://orcid.org/0000-0002-6232-7530 54 | year: '2024' 55 | url: https://github.com/e-kotov/rJavaEnv 56 | doi: 10.32614/CRAN.package.rJavaEnv 57 | repository: https://CRAN.R-project.org/package=rJavaEnv 58 | repository-code: https://github.com/e-kotov/rJavaEnv 59 | url: https://www.ekotov.pro/rJavaEnv/ 60 | contact: 61 | - family-names: Kotov 62 | given-names: Egor 63 | email: kotov.egor@gmail.com 64 | orcid: https://orcid.org/0000-0001-6690-5345 65 | keywords: 66 | - environments 67 | - java 68 | - r 69 | - reproducibility 70 | - reproducible-research 71 | references: 72 | - type: software 73 | title: 'R: A Language and Environment for Statistical Computing' 74 | notes: Depends 75 | url: https://www.R-project.org/ 76 | authors: 77 | - name: R Core Team 78 | institution: 79 | name: R Foundation for Statistical Computing 80 | address: Vienna, Austria 81 | year: '2025' 82 | version: '>= 4.0' 83 | - type: software 84 | title: checkmate 85 | abstract: 'checkmate: Fast and Versatile Argument Checks' 86 | notes: Imports 87 | url: https://mllg.github.io/checkmate/ 88 | repository: https://CRAN.R-project.org/package=checkmate 89 | authors: 90 | - family-names: Lang 91 | given-names: Michel 92 | email: michellang@gmail.com 93 | orcid: https://orcid.org/0000-0001-9754-0393 94 | year: '2025' 95 | doi: 10.32614/CRAN.package.checkmate 96 | - type: software 97 | title: cli 98 | abstract: 'cli: Helpers for Developing Command Line Interfaces' 99 | notes: Imports 100 | url: https://cli.r-lib.org 101 | repository: https://CRAN.R-project.org/package=cli 102 | authors: 103 | - family-names: Csárdi 104 | given-names: Gábor 105 | email: gabor@posit.co 106 | year: '2025' 107 | doi: 10.32614/CRAN.package.cli 108 | - type: software 109 | title: curl 110 | abstract: 'curl: A Modern and Flexible Web Client for R' 111 | notes: Imports 112 | url: https://jeroen.r-universe.dev/curl 113 | repository: https://CRAN.R-project.org/package=curl 114 | authors: 115 | - family-names: Ooms 116 | given-names: Jeroen 117 | email: jeroenooms@gmail.com 118 | orcid: https://orcid.org/0000-0002-4035-0289 119 | year: '2025' 120 | doi: 10.32614/CRAN.package.curl 121 | - type: software 122 | title: jsonlite 123 | abstract: 'jsonlite: A Simple and Robust JSON Parser and Generator for R' 124 | notes: Imports 125 | url: https://jeroen.r-universe.dev/jsonlite 126 | repository: https://CRAN.R-project.org/package=jsonlite 127 | authors: 128 | - family-names: Ooms 129 | given-names: Jeroen 130 | email: jeroenooms@gmail.com 131 | orcid: https://orcid.org/0000-0002-4035-0289 132 | year: '2025' 133 | doi: 10.32614/CRAN.package.jsonlite 134 | - type: software 135 | title: utils 136 | abstract: 'R: A Language and Environment for Statistical Computing' 137 | notes: Imports 138 | authors: 139 | - name: R Core Team 140 | institution: 141 | name: R Foundation for Statistical Computing 142 | address: Vienna, Austria 143 | year: '2025' 144 | - type: software 145 | title: quarto 146 | abstract: 'quarto: R Interface to ''Quarto'' Markdown Publishing System' 147 | notes: Suggests 148 | url: https://quarto-dev.github.io/quarto-r/ 149 | repository: https://CRAN.R-project.org/package=quarto 150 | authors: 151 | - family-names: Allaire 152 | given-names: JJ 153 | email: jj@posit.co 154 | orcid: https://orcid.org/0000-0003-0174-9868 155 | - family-names: Dervieux 156 | given-names: Christophe 157 | email: cderv@posit.co 158 | orcid: https://orcid.org/0000-0003-4474-2498 159 | year: '2025' 160 | doi: 10.32614/CRAN.package.quarto 161 | - type: software 162 | title: rJava 163 | abstract: 'rJava: Low-Level R to Java Interface' 164 | notes: Suggests 165 | url: http://www.rforge.net/rJava/ 166 | repository: https://CRAN.R-project.org/package=rJava 167 | authors: 168 | - family-names: Urbanek 169 | given-names: Simon 170 | email: simon.urbanek@r-project.org 171 | year: '2025' 172 | doi: 10.32614/CRAN.package.rJava 173 | - type: software 174 | title: testthat 175 | abstract: 'testthat: Unit Testing for R' 176 | notes: Suggests 177 | url: https://testthat.r-lib.org 178 | repository: https://CRAN.R-project.org/package=testthat 179 | authors: 180 | - family-names: Wickham 181 | given-names: Hadley 182 | email: hadley@posit.co 183 | year: '2025' 184 | doi: 10.32614/CRAN.package.testthat 185 | version: '>= 3.0.0' 186 | 187 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: rJavaEnv 2 | Title: 'Java' Environments for R Projects 3 | Version: 0.3.0.9000 4 | Authors@R: c( 5 | person("Egor", "Kotov", , "kotov.egor@gmail.com", role = c("aut", "cre", "cph"), 6 | comment = c(ORCID = "0000-0001-6690-5345")), 7 | person("Chung-hong", "Chan", , "chainsawtiney@gmail.com", role = "aut", 8 | comment = c(ORCID = "0000-0002-6232-7530")), 9 | person("Mauricio", "Vargas", , "mavargas11@uc.cl", role = "ctb", 10 | comment = c(ORCID = "0000-0003-1017-7574")), 11 | person("Hadley", "Wickham", , "hadley@posit.co", role = "ctb", 12 | comment = "use_java feature suggestion and PR review"), 13 | person("Enrique", "Mondragon-Estrada", , "enriquemondragon@proton.me", role = "ctb", 14 | comment = c(ORCID = "0009-0004-5592-1728")), 15 | person("Jonas", "Lieth", , "jonas.lieth@gesis.org", role = "ctb", 16 | comment = c(ORCID = "0000-0002-3451-3176")) 17 | ) 18 | Description: Quickly install 'Java Development Kit (JDK)' without 19 | administrative privileges and set environment variables in current R 20 | session or project to solve common issues with 'Java' environment 21 | management in 'R'. Recommended to users of 'Java'/'rJava'-dependent 22 | 'R' packages such as 'r5r', 'opentripplanner', 'xlsx', 'openNLP', 23 | 'rWeka', 'RJDBC', 'tabulapdf', and many more. 'rJavaEnv' prevents 24 | common problems like 'Java' not found, 'Java' version conflicts, 25 | missing 'Java' installations, and the inability to install 'Java' due 26 | to lack of administrative privileges. 'rJavaEnv' automates the 27 | download, installation, and setup of the 'Java' on a per-project basis 28 | by setting the relevant 'JAVA_HOME' in the current 'R' session or the 29 | current working directory (via '.Rprofile', with the user's consent). 30 | Similar to what 'renv' does for 'R' packages, 'rJavaEnv' allows 31 | different 'Java' versions to be used across different projects, but 32 | can also be configured to allow multiple versions within the same 33 | project (e.g. with the help of 'targets' package). Note: there are a 34 | few extra steps for 'Linux' users, who don't have any 'Java' 35 | previously installed in their system, and who prefer package 36 | installation from source, rather then installing binaries from 'Posit 37 | Package Manager'. See documentation for details. 38 | License: MIT + file LICENSE 39 | URL: https://github.com/e-kotov/rJavaEnv, https://www.ekotov.pro/rJavaEnv/ 40 | BugReports: https://github.com/e-kotov/rJavaEnv/issues 41 | Depends: 42 | R (>= 4.0) 43 | Imports: 44 | checkmate, 45 | cli, 46 | curl, 47 | jsonlite, 48 | utils 49 | Suggests: 50 | quarto, 51 | rJava, 52 | testthat (>= 3.0.0), 53 | withr 54 | VignetteBuilder: 55 | quarto 56 | Config/testthat/edition: 3 57 | Encoding: UTF-8 58 | Language: en-US 59 | Roxygen: list(markdown = TRUE) 60 | RoxygenNote: 7.3.2 61 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2024 2 | COPYRIGHT HOLDER: rJavaEnv authors 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2024 rJavaEnv authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(java_check_version_cmd) 4 | export(java_check_version_rjava) 5 | export(java_clear) 6 | export(java_download) 7 | export(java_env_set) 8 | export(java_env_unset) 9 | export(java_install) 10 | export(java_list) 11 | export(java_quick_install) 12 | export(java_unpack) 13 | export(java_valid_versions) 14 | export(rje_consent) 15 | export(use_java) 16 | importFrom(utils,getFromNamespace) 17 | importFrom(utils,installed.packages) 18 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # rJavaEnv (development version) 2 | 3 | # rJavaEnv 0.3.0 4 | 5 | ## New features 6 | 7 | - `Java` version (currently still only for `Amazon Corretto`) is now determined dynamically using the official GitHub `json` with releases, so when new `Java` version becomes available, you will not be depenent on `rJavaEnv` to be updated. As a fallback, versions up to 24 are hardcoded. 8 | 9 | - Added `force` argument to `java_download()`. When set to `TRUE`, allows to overwrite the distribution file if it already exist in the cache. This save the trouble of deleting the cached file with `java_clear()` before re-downloading. 10 | 11 | - Added a new function `java_valid_versions()` allows to retrieve a list of all available `Java` versions for the current automatically detected OS and CPU architecture, or user-specified platform and architecture. 12 | 13 | ## Improvements 14 | 15 | - Better command line `Java` detection (thanks to Jonas Lieth) 16 | 17 | - Test coverage is now 7.2% 18 | 19 | # rJavaEnv 0.2.2 (2024-09-13) 20 | 21 | * Hot fix: improve robustness of setting `Java` environment in the current session with either `use_java()` or `java_quick_install()`. See bug fix below. 22 | 23 | * Bug fix: Setting Java environment via `rJava::.jniInitialized()` rendered impossible changing Java version for `rJava`-dependent packages, because it somehow pre-initialised `rJava` 24 | 25 | # rJavaEnv 0.2.1 (2024-09-03) 26 | 27 | * Documentation and description clean-up 28 | 29 | # rJavaEnv 0.2.0 (2024-08-28) 30 | 31 | * Breaking change: `java_check_version_cmd()` and `java_check_version_rjava()` now return detected `Java` version instead of `TRUE`/`FALSE` 32 | 33 | * New function `use_java()` to download, install and set `Java` from cache for the current sesssion, without touching the current project/working directory. This is intended for use with `targets` and `callr`. 34 | 35 | * New vignette on using the package with `targets' and 'callr` 36 | 37 | * Updated documentation with clearer instructions on cache folder cleanup before removing the package 38 | 39 | * Depends on `R` > 4.0 to be able to write to the package cache directory without extra user warning. Cache cleanup and management functions are provided, as well as the documentation in both README and vignettes. 40 | 41 | # rJavaEnv 0.1.2 42 | 43 | * Fixed broken links in README.md 44 | 45 | # rJavaEnv 0.1.1 46 | 47 | * Improved documentation 48 | 49 | * Better handling of cache directory 50 | 51 | * Bug fixes and changes to address CRAN reviewer's comments to the first submission 52 | 53 | # rJavaEnv 0.1.0 54 | 55 | * Initial release 56 | -------------------------------------------------------------------------------- /R/consent.R: -------------------------------------------------------------------------------- 1 | #' Obtain User Consent for rJavaEnv 2 | #' 3 | #' Get user consent for rJavaEnv to write and update files on the file system. 4 | #' rJavaEnv needs permission to manage files in your project and cache directories 5 | #' to function correctly. 6 | #' 7 | #' In line with [CRAN policies](https://cran.r-project.org/web/packages/policies.html), explicit user consent is required before making these changes. 8 | #' Please call `rJavaEnv::consent()` to provide consent. 9 | #' 10 | #' Alternatively, you can set the following \R option 11 | #' (especially useful for non-interactive R sessions): 12 | #' 13 | #' ``` 14 | #' options(rJavaEnv.consent = TRUE) 15 | #' ``` 16 | #' The function is based on the code of the `renv` package. 17 | #' Copyright 2023 Posit Software, PBC 18 | #' License: https://github.com/rstudio/renv/blob/main/LICENSE 19 | #' 20 | #' @param provided Logical indicating if consent is already provided. 21 | #' To provide consent in non-interactive \R sessions 22 | #' use `rJavaEnv::rje_consent(provided = TRUE)`. Default is `FALSE`. 23 | #' 24 | #' @return `TRUE` if consent is given, otherwise an error is raised. 25 | #' 26 | #' @export 27 | #' @examples 28 | #' \dontrun{ 29 | #' 30 | #' # to provide consent and prevent other functions from interrupting to get the consent 31 | #' rje_consent(provided = TRUE) 32 | #' } 33 | #' 34 | rje_consent <- function(provided = FALSE) { 35 | 36 | # Check if consent is already given via environment variable 37 | if (getOption("rJavaEnv.consent", default = FALSE)) { 38 | cli::cli_inform("Consent for using rJavaEnv has already been provided.") 39 | return(invisible(TRUE)) 40 | } 41 | 42 | # Check if consent is already given via cache directory 43 | user_package_cache_path <- getOption("rJavaEnv.cache_path") 44 | user_package_cache_path <- normalizePath(user_package_cache_path, winslash = "/", mustWork = FALSE) 45 | if (dir.exists(user_package_cache_path)) { 46 | cli::cli_inform("Consent for using rJavaEnv has already been provided.") 47 | return(invisible(TRUE)) 48 | } 49 | 50 | # write welcome message 51 | template <- system.file("resources/consent-info", package = "rJavaEnv") 52 | contents <- readLines(template) 53 | contents <- gsub("\\$\\{rJavaEnv_CACHE\\}", user_package_cache_path, contents) 54 | cli::cli_inform(contents) 55 | 56 | # Request user consent if not already provided 57 | if (!provided) { 58 | response <- readline(prompt = "Your response: (yes/no) ") 59 | provided <- tolower(response) %in% c("y", "yes", "yes.") 60 | } 61 | 62 | if (!provided) { 63 | cli::cli_abort("Consent was not provided; operation aborted.") 64 | } 65 | 66 | # Save user consent 67 | options(rJavaEnv.consent = TRUE) 68 | dir.create(user_package_cache_path, recursive = TRUE, showWarnings = FALSE) 69 | cli::cli_inform("Consent has been granted and recorded.") 70 | 71 | invisible(TRUE) 72 | } 73 | 74 | #' Verify User Consent for rJavaEnv 75 | #' 76 | #' Ensure that the user has granted permission for rJavaEnv to manage files on their file system. 77 | #' 78 | #' The function is based on the code of the `renv` package. 79 | #' Copyright 2023 Posit Software, PBC 80 | #' License: https://github.com/rstudio/renv/blob/main/LICENSE 81 | #' 82 | #' @return `TRUE` if consent is verified, otherwise an error is raised. 83 | #' @keywords internal 84 | rje_consent_check <- function() { 85 | 86 | # Check if explicit consent is given 87 | if (getOption("rJavaEnv.consent", FALSE)) { 88 | return(TRUE) 89 | } 90 | if (dir.exists(getOption("rJavaEnv.cache_path"))) { 91 | return(TRUE) 92 | } 93 | 94 | # Check for implicit consent 95 | consented <- 96 | !interactive() || 97 | rje_envvar_exists("CI") || 98 | rje_envvar_exists("GITHUB_ACTION") || 99 | rje_envvar_exists("RENV_PATHS_ROOT") || 100 | file.exists("/.singularity.d") 101 | 102 | if (consented) { 103 | options(rJavaEnv.consent = TRUE) 104 | return(TRUE) 105 | } 106 | 107 | # Prompt for explicit consent 108 | rje_consent() 109 | } 110 | 111 | 112 | #' Helper for clean env var check 113 | #' 114 | #' #' The function is based on the code of the `renv` package. 115 | #' Copyright 2023 Posit Software, PBC 116 | #' License: https://github.com/rstudio/renv/blob/main/LICENSE 117 | #' @param key The environment variable key to check. 118 | #' @keywords internal 119 | rje_envvar_exists <- function(key) { 120 | !is.na(Sys.getenv(key, unset = NA)) 121 | } 122 | -------------------------------------------------------------------------------- /R/global_params.R: -------------------------------------------------------------------------------- 1 | #' @title Global Quiet Parameter 2 | #' 3 | #' @description 4 | #' Documentation for the `quiet` parameter, used globally. 5 | #' 6 | #' @param quiet A `logical` value indicating whether to suppress messages. Can be `TRUE` or `FALSE`. 7 | #' @keywords internal 8 | global_quiet_param <- function(quiet){ 9 | # this is just a placeholder for global quiet parameter 10 | } 11 | -------------------------------------------------------------------------------- /R/internal_utilities.R: -------------------------------------------------------------------------------- 1 | #' Detect platform and architecture 2 | #' 3 | #' @inheritParams global_quiet_param 4 | #' @keywords internal 5 | #' @return A list of length 2 with the detected platform and architecture. 6 | #' 7 | platform_detect <- function(quiet = TRUE) { 8 | sys_info <- tolower(Sys.info()) 9 | 10 | os <- switch( 11 | sys_info["sysname"], 12 | "windows" = "windows", 13 | "linux" = "linux", 14 | "darwin" = "macos", 15 | stop(cli::cli_abort("Unsupported platform")) 16 | ) 17 | 18 | arch <- switch( 19 | sys_info["machine"], 20 | "x86-64" = "x64", 21 | "x86_64" = "x64", 22 | "i386" = "x86", 23 | "i486" = "x86", 24 | "i586" = "x86", 25 | "i686" = "x86", 26 | "aarch64" = "aarch64", 27 | "arm64" = "aarch64", 28 | stop(cli::cli_abort("Unsupported architecture")) 29 | ) 30 | 31 | if (isFALSE(quiet)) { 32 | cli::cli_inform("Detected platform: {os}") 33 | cli::cli_inform("Detected architecture: {arch}") 34 | } 35 | 36 | return(list(os = os, arch = arch)) 37 | } 38 | 39 | 40 | #' Load Java URLs from JSON file 41 | #' 42 | #' @keywords internal 43 | #' 44 | #' @return A list with the Java URLs structured as in the JSON file by distribution, platform, and architecture. 45 | #' 46 | java_urls_load <- function() { 47 | json_file <- system.file("extdata", "java_urls.json", package = "rJavaEnv") 48 | if (json_file == "") { 49 | cli::cli_abort("Configuration file not found") 50 | } 51 | jsonlite::fromJSON(json_file, simplifyVector = FALSE) 52 | } 53 | 54 | #' Test all Java URLs 55 | #' 56 | #' @keywords internal 57 | #' 58 | #' @return A list with the results of testing all Java URLs. 59 | #' 60 | urls_test_all <- function() { 61 | java_urls <- java_urls_load() 62 | results <- list() 63 | 64 | for (distribution in names(java_urls)) { 65 | for (platform in names(java_urls[[distribution]])) { 66 | for (arch in names(java_urls[[distribution]][[platform]])) { 67 | url_template <- java_urls[[distribution]][[platform]][[arch]] 68 | 69 | # Replace {version} with a placeholder version to test URL 70 | url <- gsub("\\{version\\}", "11", url_template) 71 | 72 | try( 73 | { 74 | response <- curl::curl_fetch_memory( 75 | url, 76 | handle = curl::new_handle(nobody = TRUE) 77 | ) 78 | status <- response$status_code 79 | }, 80 | silent = TRUE 81 | ) 82 | 83 | if (!exists("status")) { 84 | status <- NA 85 | } 86 | 87 | results[[paste(distribution, platform, arch, sep = "-")]] <- list( 88 | url = url, 89 | status = status 90 | ) 91 | 92 | # Clear status variable for next iteration 93 | rm(status) 94 | } 95 | } 96 | } 97 | 98 | return(results) 99 | } 100 | 101 | 102 | # Unexported function to initialize Java using rJava and check Java version 103 | # This is intended to be called from the exported function java_check_version_rjava 104 | # Updated java_version_check_rscript function with verbosity control 105 | #' Check Java version using rJava 106 | #' 107 | #' @keywords internal 108 | #' 109 | #' @param java_home 110 | #' 111 | #' @return A message with the Java version or an error message. 112 | #' 113 | java_version_check_rscript <- function(java_home) { 114 | result <- tryCatch( 115 | { 116 | Sys.setenv(JAVA_HOME = java_home) 117 | 118 | old_path <- Sys.getenv("PATH") 119 | new_path <- file.path(java_home, "bin") 120 | Sys.setenv(PATH = paste(new_path, old_path, sep = .Platform$path.sep)) 121 | 122 | suppressWarnings(rJava::.jinit()) 123 | suppressWarnings( 124 | java_version <- rJava::.jcall( 125 | "java.lang.System", 126 | "S", 127 | "getProperty", 128 | "java.version" 129 | ) 130 | ) 131 | 132 | message <- cli::format_message( 133 | "rJava and other rJava/Java-based packages will use Java version: {.val {java_version}}" 134 | ) 135 | 136 | message 137 | }, 138 | error = function(e) { 139 | cli::format_message("Error checking Java version: {e$message}") 140 | } 141 | ) 142 | 143 | return(result) 144 | } 145 | -------------------------------------------------------------------------------- /R/java_download.R: -------------------------------------------------------------------------------- 1 | #' Download a Java distribution 2 | #' 3 | #' @param version `Integer` or `character` vector of length 1 for major version of Java to download or install. If not specified, defaults to the latest LTS version. Can be "8", and "11" to "24" (or the same version numers in `integer`) or any newer version if it is available for the selected distribution. For `macOS` on `aarch64` architecture (Apple Silicion) certain `Java` versions are not available. 4 | #' @param distribution The Java distribution to download. If not specified, defaults to "Amazon Corretto". Currently only \href{https://aws.amazon.com/corretto/}{"Amazon Corretto"} is supported. 5 | #' @param cache_path The destination directory to download the Java distribution to. Defaults to a user-specific data directory. 6 | #' @param platform The platform for which to download the Java distribution. Defaults to the current platform. 7 | #' @param arch The architecture for which to download the Java distribution. Defaults to the current architecture. 8 | #' @param force A logical. Whether the distribution file should be overwritten or not. Defaults to `FALSE`. 9 | #' @param temp_dir A logical. Whether the file should be saved in a temporary directory. Defaults to `FALSE`. 10 | #' @inheritParams global_quiet_param 11 | #' 12 | #' @return The path to the downloaded Java distribution file. 13 | #' @export 14 | #' 15 | #' @examples 16 | #' \dontrun{ 17 | #' 18 | #' # download distribution of Java version 17 19 | #' java_download(version = "17", temp_dir = TRUE) 20 | #' 21 | #' # download default Java distribution (version 21) 22 | #' java_download(temp_dir = TRUE) 23 | #' } 24 | java_download <- function( 25 | version = 21, 26 | distribution = "Corretto", 27 | cache_path = getOption("rJavaEnv.cache_path"), 28 | platform = platform_detect()$os, 29 | arch = platform_detect()$arch, 30 | quiet = FALSE, 31 | force = FALSE, 32 | temp_dir = FALSE 33 | ) { 34 | # Download distribution and check MD5 checksum 35 | download_dist_check_md5 <- function(url, dest_file, quiet) { 36 | curl::curl_download(url, dest_file, quiet = FALSE) 37 | curl::curl_download(url_md5, dest_file_md5, quiet = TRUE) 38 | 39 | if (!quiet) { 40 | cli::cli_inform("Download completed.", .envir = environment()) 41 | } 42 | md5sum <- tools::md5sum(dest_file) 43 | md5sum_expected <- readLines(dest_file_md5, warn = FALSE) 44 | 45 | if (md5sum != md5sum_expected) { 46 | cli::cli_abort( 47 | "MD5 checksum mismatch. Please try downloading the file again.", 48 | .envir = environment() 49 | ) 50 | unlink(dest_file) 51 | return(NULL) 52 | } else { 53 | if (!quiet) { 54 | cli::cli_inform("MD5 checksum verified.", .envir = environment()) 55 | } 56 | } 57 | } 58 | 59 | # override cache_path if temp_dir is set to TRUE 60 | if (temp_dir) { 61 | temp_dir <- tempdir() 62 | setwd(temp_dir) 63 | if (!dir.exists("rJavaEnv_cache")) { 64 | dir.create("rJavaEnv_cache", recursive = TRUE) 65 | } 66 | cache_path <- file.path(temp_dir, "rJavaEnv_cache") 67 | } 68 | 69 | # rje_consent_check() # disabling consent check for now 70 | java_urls <- java_urls_load() 71 | 72 | valid_distributions <- names(java_urls) 73 | valid_platforms <- names(java_urls[[distribution]]) 74 | valid_architectures <- names(java_urls[[distribution]][[platform]]) 75 | 76 | # Checks for the parameters 77 | checkmate::check_vector(version, len = 1) 78 | version <- as.character(version) 79 | checkmate::assert_choice( 80 | as.character(version), 81 | java_valid_versions( 82 | distribution = distribution, 83 | platform = platform, 84 | arch = arch 85 | ) 86 | ) 87 | 88 | checkmate::assert_choice(distribution, valid_distributions) 89 | 90 | # Create the distrib subfolder within the destination directory 91 | cache_path <- file.path(cache_path, "distrib") 92 | if (!dir.exists(cache_path)) { 93 | dir.create(cache_path, recursive = TRUE) 94 | } 95 | checkmate::assert_directory_exists(cache_path, access = "rw", add = TRUE) 96 | 97 | checkmate::assert_choice(platform, valid_platforms) 98 | checkmate::assert_choice(arch, valid_architectures) 99 | checkmate::assert_flag(quiet) 100 | checkmate::assert_flag(force) 101 | 102 | # Print out the detected platform and architecture 103 | if (!quiet) { 104 | cli::cli_inform(c( 105 | "Detected platform: {.strong {platform}}", 106 | "Detected architecture: {.strong {arch}}", 107 | "You can change the platform and architecture by specifying the {.arg platform} and {.arg arch} arguments." 108 | )) 109 | } 110 | 111 | if (!distribution %in% names(java_urls)) { 112 | cli::cli_abort( 113 | "Unsupported distribution: {.val {distribution}}", 114 | .envir = environment() 115 | ) 116 | } 117 | 118 | if (!platform %in% names(java_urls[[distribution]])) { 119 | cli::cli_abort( 120 | "Unsupported platform: {.val {platform}}", 121 | .envir = environment() 122 | ) 123 | } 124 | 125 | if (!arch %in% names(java_urls[[distribution]][[platform]])) { 126 | cli::cli_abort( 127 | "Unsupported architecture: {.val {arch}}", 128 | .envir = environment() 129 | ) 130 | } 131 | 132 | url_template <- java_urls[[distribution]][[platform]][[arch]] 133 | url <- gsub("\\{version\\}", version, url_template) 134 | url_md5 <- gsub("latest/", "latest_checksum/", url) 135 | 136 | dest_file <- file.path(cache_path, basename(url)) 137 | dest_file_md5 <- paste0(file.path(cache_path, basename(url_md5)), ".md5") 138 | 139 | if (!quiet) { 140 | cli::cli_inform( 141 | "Downloading Java {version} ({distribution}) for {platform} {arch} to {dest_file}", 142 | .envir = environment() 143 | ) 144 | } 145 | 146 | if (file.exists(dest_file) & !force) { 147 | if (!quiet) { 148 | cli::cli_inform( 149 | "File already exists. Skipping download.", 150 | .envir = environment() 151 | ) 152 | } 153 | return(dest_file) 154 | } 155 | 156 | if (file.exists(dest_file) & force) { 157 | if (!quiet) { 158 | cli::cli_inform("Removing existing installation.", .envir = environment()) 159 | } 160 | file.remove(dest_file) 161 | } 162 | 163 | download_dist_check_md5(url, dest_file, quiet) 164 | 165 | return(dest_file) 166 | } 167 | -------------------------------------------------------------------------------- /R/java_install.R: -------------------------------------------------------------------------------- 1 | #' Install Java from a distribution file 2 | #' 3 | #' @description 4 | #' Unpack Java distribution file into cache directory and link the installation into a project directory, optionally setting the `JAVA_HOME` and `PATH` environment variables to the Java version that was just installed. 5 | #' 6 | #' @param java_distrib_path A `character` vector of length 1 containing the path to the Java distribution file. 7 | #' @param project_path A `character` vector of length 1 containing the project directory where Java should be installed. If not specified or `NULL`, defaults to the current working directory. 8 | #' @param autoset_java_env A `logical` indicating whether to set the `JAVA_HOME` and `PATH` environment variables to the installed Java directory. Defaults to `TRUE`. 9 | #' @inheritParams java_download 10 | #' @inheritParams global_quiet_param 11 | #' @return The path to the installed Java directory. 12 | #' @export 13 | #' 14 | #' @examples 15 | #' \dontrun{ 16 | #' 17 | #' # set cache dir to temporary directory 18 | #' options(rJavaEnv.cache_path = tempdir()) 19 | #' # download, install and autoset environmnet variables for Java 17 20 | #' java_17_distrib <- java_download(version = "17") 21 | #' java_install(java_distrib_path = java_17_distrib, project_path = tempdir()) 22 | #' } 23 | java_install <- function( 24 | java_distrib_path, 25 | project_path = NULL, 26 | autoset_java_env = TRUE, 27 | quiet = FALSE 28 | ) { 29 | rje_consent_check() 30 | 31 | # Resolve the project path 32 | # consistent with renv behavior 33 | # https://github.com/rstudio/renv/blob/d6bced36afa0ad56719ca78be6773e9b4bbb078f/R/init.R#L69-L86 34 | project_path <- ifelse(is.null(project_path), getwd(), project_path) 35 | 36 | installed_path <- java_unpack( 37 | java_distrib_path = java_distrib_path, 38 | quiet = quiet 39 | ) 40 | 41 | platforms <- c("windows", "linux", "macos") 42 | architectures <- c("x64", "aarch64", "arm64") 43 | java_versions <- java_valid_versions() 44 | 45 | # Extract information from the file name 46 | filename <- basename(java_distrib_path) 47 | parts <- strsplit(gsub("\\.tar\\.gz|\\.zip", "", filename), "-")[[1]] 48 | 49 | # Guess the version, architecture, and platform 50 | version <- parts[vapply(parts, function(x) x %in% java_versions, logical(1))][ 51 | 1 52 | ] 53 | arch <- parts[vapply(parts, function(x) x %in% architectures, logical(1))][1] 54 | platform <- parts[vapply(parts, function(x) x %in% platforms, logical(1))][1] 55 | 56 | # Create a symlink in the project directory 57 | project_version_path <- file.path( 58 | project_path, 59 | "rjavaenv", 60 | platform, 61 | arch, 62 | version 63 | ) 64 | if (!dir.exists(dirname(project_version_path))) { 65 | dir.create(dirname(project_version_path), recursive = TRUE) 66 | } 67 | 68 | link_success <- FALSE 69 | if (.Platform$OS.type == "windows") { 70 | try( 71 | { 72 | if (file.exists(project_version_path)) { 73 | unlink(project_version_path, recursive = TRUE) 74 | } 75 | cmd <- sprintf( 76 | "mklink /J \"%s\" \"%s\"", 77 | gsub("/", "\\\\", project_version_path), 78 | gsub("/", "\\\\", installed_path) 79 | ) 80 | result <- tryCatch( 81 | system2("cmd.exe", args = c("/c", cmd), stdout = TRUE, stderr = TRUE), 82 | warning = function(w) { 83 | # if (!quiet) cli::cli_inform("Warning: {w}") 84 | NULL 85 | }, 86 | error = function(e) { 87 | # if (!quiet) cli::cli_inform("Error: {e}") 88 | NULL 89 | } 90 | ) 91 | if (!is.null(result) && any(grepl("Junction created", result))) { 92 | link_success <- TRUE 93 | } 94 | }, 95 | silent = TRUE 96 | ) 97 | if (!link_success) { 98 | if (!quiet) 99 | cli::cli_inform( 100 | "Junction creation failed. This is likely because the project directory is not on the same disk as the R package cache directory. Java files will instead be copied to {.path {project_version_path}}" 101 | ) 102 | dir.create(project_version_path, recursive = TRUE) 103 | file.copy( 104 | installed_path, 105 | project_version_path, 106 | recursive = TRUE, 107 | overwrite = TRUE 108 | ) 109 | if (!quiet) 110 | cli::cli_inform("Java copied to project {.path {project_version_path}}") 111 | } 112 | } else { 113 | tryCatch( 114 | { 115 | if (file.exists(project_version_path)) { 116 | unlink(project_version_path, recursive = TRUE) 117 | } 118 | file.symlink(installed_path, project_version_path) 119 | }, 120 | warning = function(w) { 121 | if (!quiet) cli::cli_inform("Warning: {w}") 122 | }, 123 | error = function(e) { 124 | if (!quiet) cli::cli_inform("Error: {e}") 125 | dir.create(project_version_path, recursive = TRUE) 126 | file.copy( 127 | installed_path, 128 | project_version_path, 129 | recursive = TRUE, 130 | overwrite = TRUE 131 | ) 132 | if (!quiet) 133 | cli::cli_inform( 134 | "Symlink creation failed. Files copied to {.path {project_version_path}}" 135 | ) 136 | } 137 | ) 138 | } 139 | 140 | # Write the JAVA_HOME to the .Rprofile and environment after installation 141 | if (autoset_java_env) { 142 | java_env_set( 143 | installed_path, 144 | where = "both", 145 | quiet = quiet, 146 | project_path = project_path 147 | ) 148 | } 149 | 150 | if (!quiet) 151 | cli::cli_inform( 152 | "Java {version} ({filename}) for {platform} {arch} installed at {.path {installed_path}} and symlinked to {.path {project_version_path}}", 153 | .envir = environment() 154 | ) 155 | return(installed_path) 156 | } 157 | -------------------------------------------------------------------------------- /R/java_manage.R: -------------------------------------------------------------------------------- 1 | #' List the contents of the Java versions installed or cached 2 | #' 3 | #' @description 4 | #' This function lists one of the following: 5 | #' 6 | #' * `project` - list the contents of the Java symlinked/copied in the current project or directory specified by `target_dir` 7 | #' 8 | #' * `distrib` - list the contents of the downloaded Java distributions cache in default location or specified by `target_dir` 9 | #' 10 | #' * `installed` - list the contents of the Java installations cache (unpacked distributions) in default location or specified by `target_dir` 11 | #' 12 | #' @param type The type of cache to list: "distrib", "installed", or "project". Defaults to "project". 13 | #' @param output The format of the output: `data.frame`` or `vector``. Defaults to `data.frame`. 14 | #' @inheritParams global_quiet_param 15 | #' @param target_dir The cache directory to list. Defaults to the user-specific data directory for "distrib" and "installed", and the current working directory for "project". 16 | #' @return A `dataframe` or `character` `vector` with the contents of the specified cache or project directory. 17 | #' @export 18 | #' 19 | #' @examples 20 | #' \dontrun{ 21 | #' java_list("project") 22 | #' java_list("installed") 23 | #' java_list("distrib") 24 | #'} 25 | #' 26 | java_list <- function( 27 | type = c("project", "installed", "distrib"), 28 | output = c("data.frame", "vector"), 29 | quiet = TRUE, 30 | target_dir = NULL) { 31 | type <- match.arg(type) 32 | output <- match.arg(output) 33 | 34 | if (is.null(target_dir)) { 35 | if (type == "project") { 36 | target_dir <- getwd() 37 | } else { 38 | target_dir <- getOption("rJavaEnv.cache_path") 39 | } 40 | } 41 | 42 | if (type == "distrib") { 43 | return(java_list_distrib_cache(output = output, quiet = quiet, cache_path = target_dir)) 44 | } else if (type == "installed") { 45 | return(java_list_installed_cache(output = output, quiet = quiet, cache_path = target_dir)) 46 | } else if (type == "project") { 47 | return(java_list_in_project(output = output, quiet = quiet, project_path = target_dir)) 48 | } 49 | } 50 | 51 | #' Manage Java installations and distributions caches 52 | #' 53 | #' Wrapper function to clear the Java symlinked in the current project, installed, or distributions caches. 54 | #' 55 | #' @param type What to clear: "project" - remove symlinks to install cache in the current project, "installed" - remove installed Java versions, "distrib" - remove downloaded Java distributions. 56 | #' @param check Whether to list the contents of the cache directory before clearing it. Defaults to TRUE. 57 | #' @param delete_all Whether to delete all items without prompting. Defaults to FALSE. 58 | #' @param target_dir The directory to clear. Defaults to current working directory for "project" and user-specific data directory for "installed" and "distrib". Not recommended to change. 59 | #' @return A message indicating whether the cache was cleared or not. 60 | #' @export 61 | #' 62 | #' @examples 63 | #' \dontrun{ 64 | #' java_clear("project", target_dir = tempdir()) 65 | #' java_clear("installed", target_dir = tempdir()) 66 | #' java_clear("distrib", target_dir = tempdir()) 67 | #' } 68 | #' 69 | java_clear <- function( 70 | type = c("project", "installed", "distrib"), 71 | target_dir = NULL, 72 | check = TRUE, 73 | delete_all = FALSE) { 74 | rje_consent_check() 75 | 76 | type <- match.arg(type) 77 | 78 | if (is.null(target_dir)) { 79 | if (type == "project") { 80 | target_dir <- getwd() 81 | } else { 82 | target_dir <- getOption("rJavaEnv.cache_path") 83 | } 84 | } 85 | 86 | if (type == "distrib") { 87 | java_clear_distrib_cache(cache_path = target_dir, check = check, delete_all = delete_all) 88 | } else if (type == "installed") { 89 | java_clear_installed_cache(cache_path = target_dir, check = check, delete_all = delete_all) 90 | } else if (type == "project") { 91 | java_clear_in_project(project_path = target_dir, check = check, delete_all = delete_all) 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /R/java_manage_distrib_cache.R: -------------------------------------------------------------------------------- 1 | #' List the contents of the Java distributions cache folder 2 | #' 3 | #' @param output The format of the output: "data.frame" or "vector". Defaults to "data.frame". 4 | #' @inheritParams java_list 5 | #' @inheritParams java_download 6 | #' @inheritParams global_quiet_param 7 | #' @return A character vector with the contents of the cache directory. 8 | #' 9 | #' @keywords internal 10 | java_list_distrib_cache <- function( 11 | cache_path = getOption("rJavaEnv.cache_path"), 12 | output = c("data.frame", "vector"), 13 | quiet = TRUE 14 | ) { 15 | output <- match.arg(output) 16 | 17 | cache_path <- file.path(cache_path, "distrib") 18 | 19 | if (!dir.exists(cache_path)) { 20 | cli::cli_alert_danger("No Java distributions have been downloaded.") 21 | return(character(0)) 22 | } 23 | if (!quiet) cli::cli_inform("Contents of the Java distributions cache folder:") 24 | 25 | java_distrs <- grep( 26 | "md5$", 27 | list.files(cache_path, full.names = TRUE), 28 | invert = TRUE, 29 | value = TRUE 30 | ) 31 | 32 | if (output == "vector") { 33 | return(java_distrs) 34 | } else if (output == "data.frame") { 35 | java_distrs <- data.frame(java_distr_path = java_distrs) 36 | return(java_distrs) 37 | } 38 | } 39 | 40 | #' Clear the Java distributions cache folder 41 | #' 42 | #' @param cache_path The cache directory to clear. Defaults to the user-specific data directory. 43 | #' @inheritParams java_clear 44 | #' @inheritParams java_download 45 | #' @return A message indicating whether the cache was cleared or not. 46 | #' 47 | #' @keywords internal 48 | java_clear_distrib_cache <- function( 49 | cache_path = getOption("rJavaEnv.cache_path"), 50 | check = TRUE, 51 | delete_all = FALSE 52 | ) { 53 | rje_consent_check() 54 | 55 | distrib_cache_path <- file.path(cache_path, "distrib") 56 | 57 | if (!dir.exists(distrib_cache_path)) { 58 | if (length(list.files(distrib_cache_path)) == 0) { 59 | cli::cli_inform("Java distributions cache is already empty.") 60 | return(invisible(NULL)) 61 | } 62 | } 63 | 64 | if (delete_all) { 65 | unlink(file.path(distrib_cache_path, "*"), recursive = TRUE) 66 | cli::cli_inform("Java distributions cache cleared.") 67 | return(invisible(NULL)) 68 | } 69 | 70 | if (check) { 71 | distributions <- java_list_distrib_cache(output = "vector", cache_path = cache_path) 72 | if (length(distributions) == 0) { 73 | cli::cli_inform("No Java distributions found to clear.") 74 | return(invisible(NULL)) 75 | } 76 | 77 | cli::cli_alert_info("Existing Java distributions:") 78 | for (i in seq_along(distributions)) { 79 | cli::cli_inform("{i}: {distributions[i]}") 80 | } 81 | 82 | cli::cli_alert_info("Enter the number of the distribution to delete, 'all' to delete all, or '0' or any other character to cancel:") 83 | response <- readline() 84 | 85 | if (tolower(response) == "all") { 86 | unlink(file.path(distrib_cache_path, "*"), recursive = TRUE) 87 | cli::cli_inform("All Java distributions have been cleared.") 88 | } else { 89 | choice <- suppressWarnings(as.integer(response)) 90 | if (is.na(choice) || choice == 0 || choice > length(distributions)) { 91 | cli::cli_inform("No distributions were cleared.") 92 | } else { 93 | unlink(distributions[choice], recursive = TRUE) 94 | md5_file <- paste0(distributions[choice], "md5") 95 | if(file.exists(md5_file)) unlink(md5_file) 96 | cli::cli_inform("Java distribution {choice} has been cleared.") 97 | } 98 | } 99 | } else { 100 | cli::cli_alert_info("Are you sure you want to clear the Java distributions cache? (yes/no)") 101 | response <- readline() 102 | if (tolower(response) == "yes") { 103 | unlink(file.path(distrib_cache_path, "*"), recursive = TRUE) 104 | cli::cli_inform("Java distributions cache cleared.") 105 | } else { 106 | cli::cli_inform("Java distributions cache was not cleared.") 107 | } 108 | } 109 | 110 | return(invisible(NULL)) 111 | } 112 | -------------------------------------------------------------------------------- /R/java_manage_installed_cache.R: -------------------------------------------------------------------------------- 1 | #' List the contents of the Java installations cache folder 2 | #' 3 | #' @param output The format of the output: "data.frame" or "vector". Defaults to "data.frame". 4 | #' @param cache_path The cache directory to list. Defaults to the user-specific data directory. Not recommended to change. 5 | #' @inheritParams global_quiet_param 6 | #' @return A data frame or character vector with the contents of the cache directory. 7 | #' @keywords internal 8 | java_list_installed_cache <- function( 9 | output = c("data.frame", "vector"), 10 | quiet = TRUE, 11 | cache_path = getOption("rJavaEnv.cache_path") 12 | ) { 13 | output <- match.arg(output) 14 | installed_cache_path <- file.path(cache_path, "installed") 15 | 16 | if (!dir.exists(installed_cache_path)) { 17 | cli::cli_alert_danger("No Java distributions have been installed yet.") 18 | return(character(0)) 19 | } 20 | 21 | if (!quiet) cli::cli_inform("Contents of the Java installations cache folder:") 22 | 23 | # List directories up to the specified depth 24 | java_paths <- list.dirs(installed_cache_path, recursive = TRUE, full.names = TRUE) 25 | 26 | java_paths <- java_paths[vapply(java_paths, function(x) { 27 | length(strsplit(x, .Platform$file.sep)[[1]]) == length(strsplit(installed_cache_path, .Platform$file.sep)[[1]]) + 3 28 | }, logical(1))] 29 | 30 | if (length(java_paths) == 0) { 31 | return(character(0)) 32 | } 33 | 34 | if (output == "vector") { 35 | return(unname(java_paths)) 36 | } else if (output == "data.frame") { 37 | java_info <- lapply(java_paths, function(path) { 38 | parts <- strsplit(path, .Platform$file.sep)[[1]] 39 | parts <- parts[(length(parts) - 2):length(parts)] 40 | names(parts) <- c("platform", "arch", "version") 41 | parts <- c(path = path, parts) 42 | return(parts) 43 | }) 44 | java_info_df <- do.call(rbind, lapply(java_info, function(info) as.data.frame(t(info), stringsAsFactors = FALSE))) 45 | rownames(java_info_df) <- NULL 46 | return(java_info_df) 47 | } 48 | } 49 | 50 | #' Clear the Java installations cache folder 51 | #' 52 | #' @param cache_path The cache directory to clear. Defaults to the user-specific data directory. 53 | #' @param check Whether to list the contents of the cache directory before clearing it. Defaults to TRUE. 54 | #' @param delete_all Whether to delete all installations without prompting. Defaults to FALSE. 55 | #' @return A message indicating whether the cache was cleared or not. 56 | #' 57 | #' @keywords internal 58 | java_clear_installed_cache <- function( 59 | check = TRUE, 60 | delete_all = FALSE, 61 | cache_path = getOption("rJavaEnv.cache_path") 62 | ) { 63 | rje_consent_check() 64 | 65 | installed_cache_path <- file.path(cache_path, "installed") 66 | 67 | if (!dir.exists(installed_cache_path)) { 68 | cli::cli_inform("Java installations cache is already empty.") 69 | return(invisible(NULL)) 70 | } 71 | 72 | if (delete_all) { 73 | unlink(file.path(installed_cache_path, "*"), recursive = TRUE) 74 | cli::cli_inform("Java installations cache cleared.") 75 | return(invisible(NULL)) 76 | } 77 | 78 | if (check) { 79 | installations <- java_list_installed_cache(cache_path, quiet = FALSE, output = "vector") 80 | if (length(installations) == 0) { 81 | cli::cli_inform("No Java installations found to clear.") 82 | return(invisible(NULL)) 83 | } 84 | 85 | cli::cli_alert_info("Existing Java installations:") 86 | for (i in seq_along(installations)) { 87 | cli::cli_inform("{i}: {installations[i]}") 88 | } 89 | 90 | cli::cli_alert_info("Enter the number of the installation to delete, 'all' to delete all, or '0' or any other character to cancel:") 91 | response <- readline() 92 | 93 | if (tolower(response) == "all") { 94 | unlink(file.path(installed_cache_path, "*"), recursive = TRUE) 95 | cli::cli_inform("All Java installations have been cleared.") 96 | } else { 97 | choice <- suppressWarnings(as.integer(response)) 98 | if (is.na(choice) || choice == 0 || choice > length(installations)) { 99 | cli::cli_inform("No installations were cleared.") 100 | } else { 101 | unlink(installations[choice], recursive = TRUE) 102 | cli::cli_inform("Java installation {choice} has been cleared.") 103 | } 104 | } 105 | } else { 106 | cli::cli_alert_info("Are you sure you want to clear the Java installations cache? (yes/no)") 107 | response <- readline() 108 | if (tolower(response) == "yes") { 109 | unlink(file.path(installed_cache_path, "*"), recursive = TRUE) 110 | cli::cli_inform("Java installations cache cleared.") 111 | } else { 112 | cli::cli_inform("Java installations cache was not cleared.") 113 | } 114 | } 115 | 116 | return(invisible(NULL)) 117 | } 118 | -------------------------------------------------------------------------------- /R/java_manage_project.R: -------------------------------------------------------------------------------- 1 | #' List the Java versions symlinked in the current project 2 | #' 3 | #' @param project_path The project directory to list. Defaults to the current working directory. 4 | #' @param output The format of the output: "data.frame" or "vector". Defaults to "data.frame". 5 | #' @inheritParams global_quiet_param 6 | #' @return A data frame or character vector with the symlinked Java versions in the project directory. 7 | #' @keywords internal 8 | java_list_in_project <- function( 9 | project_path = NULL, 10 | output = c("data.frame", "vector"), 11 | quiet = TRUE 12 | ) { 13 | 14 | # Resolve the project path 15 | # consistent with renv behavior 16 | # https://github.com/rstudio/renv/blob/d6bced36afa0ad56719ca78be6773e9b4bbb078f/R/init.R#L69-L86 17 | project_path <- ifelse(is.null(project_path), getwd(), project_path) 18 | 19 | output <- match.arg(output) 20 | java_symlink_dir <- file.path(project_path, "rjavaenv") 21 | 22 | if (!dir.exists(java_symlink_dir)) { 23 | cli::cli_alert_danger("No Java has been installed in the project.") 24 | return(invisible(NULL)) 25 | } 26 | 27 | 28 | # List directories up to the specified depth 29 | java_paths <- list.dirs(java_symlink_dir, recursive = TRUE, full.names = TRUE) 30 | 31 | java_paths <- java_paths[vapply(java_paths, function(x) { 32 | length(strsplit(x, .Platform$file.sep)[[1]]) == length(strsplit(java_symlink_dir, .Platform$file.sep)[[1]]) + 3 33 | }, logical(1))] 34 | 35 | if (length(java_paths) == 0) { 36 | cli::cli_alert_danger("No Java has been installed in the project.") 37 | return(invisible(NULL)) 38 | } 39 | 40 | if (!quiet) cli::cli_inform("Contents of the Java symlinks in the project folder:") 41 | 42 | if (output == "vector") { 43 | return(unname(java_paths)) 44 | } else if (output == "data.frame") { 45 | java_info <- lapply(java_paths, function(path) { 46 | parts <- strsplit(path, .Platform$file.sep)[[1]] 47 | parts <- parts[(length(parts) - 2):length(parts)] 48 | names(parts) <- c("platform", "arch", "version") 49 | parts <- c(path = path, parts) 50 | return(parts) 51 | }) 52 | java_info_df <- do.call(rbind, lapply(java_info, function(info) as.data.frame(t(info), stringsAsFactors = FALSE))) 53 | rownames(java_info_df) <- NULL 54 | return(java_info_df) 55 | } 56 | } 57 | 58 | #' Clear the Java versions symlinked in the current project 59 | #' 60 | #' @param project_path The project directory to clear. Defaults to the current working directory. 61 | #' @param check Whether to list the symlinked Java versions before clearing them. Defaults to TRUE. 62 | #' @param delete_all Whether to delete all symlinks without prompting. Defaults to FALSE. 63 | #' @return A message indicating whether the symlinks were cleared or not. 64 | #' 65 | #' @keywords internal 66 | java_clear_in_project <- function( 67 | project_path = NULL, 68 | check = TRUE, 69 | delete_all = FALSE 70 | ) { 71 | rje_consent_check() 72 | 73 | # Resolve the project path 74 | # consistent with renv behavior 75 | # https://github.com/rstudio/renv/blob/d6bced36afa0ad56719ca78be6773e9b4bbb078f/R/init.R#L69-L86 76 | project_path <- ifelse(is.null(project_path), getwd(), project_path) 77 | 78 | java_symlink_dir <- file.path(project_path, "rjavaenv") 79 | 80 | if (!dir.exists(java_symlink_dir)) { 81 | cli::cli_inform("Java symlink directory does not exist in the project.") 82 | return(invisible(NULL)) 83 | } 84 | 85 | if (delete_all) { 86 | unlink(file.path(java_symlink_dir), recursive = TRUE) 87 | cli::cli_inform("All Java symlinks in the project have been cleared.") 88 | return(invisible(NULL)) 89 | } 90 | 91 | if (check) { 92 | symlinks <- java_list_in_project(project_path = project_path, output = "vector") 93 | if (length(symlinks) == 0) { 94 | cli::cli_inform("No Java symlinks found to clear.") 95 | return(invisible(NULL)) 96 | } 97 | 98 | cli::cli_alert_info("Existing Java symlinks:") 99 | for (i in seq_along(symlinks)) { 100 | cli::cli_inform("{i}: {symlinks[i]}") 101 | } 102 | 103 | cli::cli_alert_info("Enter the number of the symlink to delete, 'all' to delete all, or '0' or any other character to cancel:") 104 | response <- readline() 105 | 106 | if (tolower(response) == "all") { 107 | unlink(file.path(java_symlink_dir, "*"), recursive = TRUE) 108 | cli::cli_inform("All Java symlinks in the project have been cleared.") 109 | } else { 110 | choice <- suppressWarnings(as.integer(response)) 111 | if (is.na(choice) || choice == 0 || choice > length(symlinks)) { 112 | cli::cli_inform("No symlinks were cleared.") 113 | } else { 114 | unlink(symlinks[choice], recursive = TRUE) 115 | cli::cli_inform("Java symlink {choice} has been cleared.") 116 | } 117 | } 118 | } else { 119 | cli::cli_alert_info("Are you sure you want to clear all Java symlinks in the project? (yes/no)") 120 | response <- readline() 121 | if (tolower(response) == "yes") { 122 | unlink(file.path(java_symlink_dir, "*"), recursive = TRUE) 123 | cli::cli_inform("All Java symlinks in the project have been cleared.") 124 | } else { 125 | cli::cli_inform("No Java symlinks were cleared.") 126 | } 127 | } 128 | 129 | return(invisible(NULL)) 130 | } 131 | -------------------------------------------------------------------------------- /R/java_quick_install.R: -------------------------------------------------------------------------------- 1 | #' Download and install and set Java in current working/project directory 2 | #' 3 | #' @inheritParams java_download 4 | #' @inheritParams java_install 5 | #' @inheritParams global_quiet_param 6 | #' @return Message indicating that Java was installed and set in the current working/project directory. 7 | #' @export 8 | #' 9 | #' @examples 10 | #' \dontrun{ 11 | #' 12 | #' # quick download, unpack, install and set in current working directory default Java version (21) 13 | #' java_quick_install(17, temp_dir = TRUE) 14 | #' } 15 | java_quick_install <- function( 16 | version = 21, 17 | distribution = "Corretto", 18 | project_path = NULL, 19 | platform = platform_detect()$os, 20 | arch = platform_detect()$arch, 21 | quiet = FALSE, 22 | temp_dir = FALSE 23 | ) { 24 | rje_consent_check() 25 | 26 | if (temp_dir) { 27 | temp_dir <- tempdir() 28 | setwd(temp_dir) 29 | if (!dir.exists("rJavaEnv_cache")) { 30 | dir.create("rJavaEnv_cache", recursive = TRUE) 31 | } 32 | cache_path <- file.path(temp_dir, "rJavaEnv_cache") 33 | if (!dir.exists("rJavaEnv_project")) { 34 | dir.create("rJavaEnv_project", recursive = TRUE) 35 | } 36 | project_path <- file.path(temp_dir, "rJavaEnv_project") 37 | } else { 38 | cache_path <- getOption("rJavaEnv.cache_path") 39 | } 40 | 41 | java_distrib_path <- java_download( 42 | version = version, 43 | distribution = distribution, 44 | cache_path = cache_path, 45 | platform = platform, 46 | arch = arch, 47 | quiet = quiet 48 | ) 49 | 50 | java_install( 51 | java_distrib_path, 52 | project_path = project_path, 53 | autoset_java_env = TRUE, 54 | quiet = quiet 55 | ) 56 | return(invisible(NULL)) 57 | } 58 | -------------------------------------------------------------------------------- /R/java_unpack.R: -------------------------------------------------------------------------------- 1 | #' Unpack a Java distribution file into cache directory 2 | #' 3 | #' @description 4 | #' Unpack the Java distribution file into cache directory and return the path to the unpacked Java directory with Java binaries. 5 | #' 6 | #' 7 | #' @inheritParams java_install 8 | #' @inheritParams global_quiet_param 9 | #' @return A `character` vector containing of length 1 containing the path to the unpacked Java directory. 10 | #' @export 11 | #' @examples 12 | #' \dontrun{ 13 | #' 14 | #' # set cache dir to temporary directory 15 | #' options(rJavaEnv.cache_path = tempdir()) 16 | #' 17 | #' # download Java 17 distrib and unpack it into cache dir 18 | #' java_17_distrib <- java_download(version = "17") 19 | #' java_home <- java_unpack(java_distrib_path = java_17_distrib) 20 | #' 21 | #' # set the JAVA_HOME environment variable in the current session 22 | #' # to the cache dir without touching any files in the current project directory 23 | #' java_env_set(where = "session", java_home = java_home) 24 | #' } 25 | #' 26 | java_unpack <- function( 27 | java_distrib_path, 28 | quiet = FALSE 29 | ) { 30 | platforms <- c("windows", "linux", "macos") 31 | architectures <- c("x64", "aarch64", "arm64") 32 | java_versions <- java_valid_versions() 33 | 34 | # Extract information from the file name 35 | filename <- basename(java_distrib_path) 36 | parts <- strsplit(gsub("\\.tar\\.gz|\\.zip", "", filename), "-")[[1]] 37 | 38 | # Guess the version, architecture, and platform 39 | version <- parts[parts %in% java_versions][1] 40 | arch <- parts[parts %in% architectures][1] 41 | platform <- parts[parts %in% platforms][1] 42 | 43 | if (is.na(version)) 44 | cli::cli_abort("Unable to detect Java version from filename.") 45 | if (is.na(arch)) 46 | cli::cli_abort("Unable to detect architecture from filename.") 47 | if (is.na(platform)) 48 | cli::cli_abort("Unable to detect platform from filename.") 49 | 50 | # Create the installation path in the package cache 51 | cache_path <- getOption("rJavaEnv.cache_path") 52 | installed_path <- file.path(cache_path, "installed", platform, arch, version) 53 | 54 | # Check if the distribution has already been unpacked 55 | if (!dir.exists(installed_path) || length(list.files(installed_path)) == 0) { 56 | # Create the directories if they don't exist 57 | if (!dir.exists(installed_path)) { 58 | dir.create(installed_path, recursive = TRUE) 59 | } 60 | 61 | # Determine extraction path based on platform 62 | if (platform == "macos") { 63 | extract_subdir <- "Contents/Home" 64 | } else { 65 | extract_subdir <- "." 66 | } 67 | 68 | # Extract the files 69 | temp_dir <- file.path(tempdir(), "java_temp") 70 | if (dir.exists(temp_dir)) { 71 | unlink(temp_dir, recursive = TRUE) 72 | } 73 | 74 | dir.create(temp_dir, recursive = TRUE) 75 | 76 | if (grepl("\\.tar\\.gz$", java_distrib_path)) { 77 | utils::untar(java_distrib_path, exdir = temp_dir) 78 | } else if (grepl("\\.zip$", java_distrib_path)) { 79 | utils::unzip(java_distrib_path, exdir = temp_dir) 80 | } else { 81 | stop(cli::cli_abort("Unsupported file format", .envir = environment())) 82 | } 83 | 84 | # Safely find the extracted directory 85 | extracted_root_dir <- list.files(temp_dir, full.names = TRUE)[1] 86 | if (platform == "macos") { 87 | extracted_dir <- file.path(extracted_root_dir, "Contents", "Home") 88 | } else { 89 | extracted_dir <- extracted_root_dir 90 | } 91 | 92 | # Move the extracted files to the installation path 93 | file.copy( 94 | list.files(extracted_dir, full.names = TRUE), 95 | installed_path, 96 | recursive = TRUE 97 | ) 98 | 99 | # Clean up temporary directory 100 | unlink(temp_dir, recursive = TRUE) 101 | } else { 102 | if (!quiet) 103 | cli::cli_inform( 104 | "Java distribution {filename} already unpacked at {.path {installed_path}}" 105 | ) 106 | } 107 | return(installed_path) 108 | } 109 | -------------------------------------------------------------------------------- /R/java_valid_versions.R: -------------------------------------------------------------------------------- 1 | #' Retrieve Valid Java Versions 2 | #' 3 | #' This function retrieves a list of valid Java versions by querying an appropriate API endpoint based on the chosen distribution. 4 | #' The result is cached for 8 hours to avoid repeated API calls. If the API call fails (for example, due to a lack of internet connectivity), 5 | #' the function falls back to a pre-defined list of Java versions. 6 | #' 7 | #' @inheritParams java_download 8 | #' 9 | #' @param force Logical. If TRUE, forces a fresh API call even if a cached value exists. Defaults to FALSE. 10 | #' 11 | #' @return A character vector of valid Java versions. 12 | #' 13 | #' @examples 14 | #' \dontrun{ 15 | #' # Retrieve valid Java versions (cached if available) using Amazon Corretto endpoint 16 | #' versions <- java_valid_versions() 17 | #' 18 | #' # Force refresh the list of Java versions using the Oracle endpoint 19 | #' versions <- java_valid_versions(distribution = "Corretto", force = TRUE) 20 | #' } 21 | #' 22 | #' @export 23 | #' 24 | java_valid_versions <- function( 25 | distribution = "Corretto", 26 | platform = platform_detect()$os, 27 | arch = platform_detect()$arch, 28 | force = FALSE 29 | ) { 30 | # Define cache expiry time (in hours) 31 | expiry_hours <- 8 32 | 33 | # Retrieve cached values from options 34 | valid_versions_cache <- getOption("rJavaEnv.valid_versions_cache") 35 | valid_versions_timestamp <- getOption("rJavaEnv.valid_versions_timestamp") 36 | 37 | # Return cached value if available and not expired, unless force is TRUE. 38 | if ( 39 | !force && 40 | !is.null(valid_versions_cache) && 41 | !is.null(valid_versions_timestamp) && 42 | as.numeric(difftime( 43 | Sys.time(), 44 | valid_versions_timestamp, 45 | units = "hours" 46 | )) < 47 | expiry_hours 48 | ) { 49 | return(valid_versions_cache) 50 | } 51 | 52 | # Select helper based on distribution value. 53 | new_versions <- switch( 54 | distribution, 55 | # "Oracle" = java_valid_versions_oracle(), 56 | "Corretto" = java_valid_major_versions_corretto( 57 | platform = platform, 58 | arch = arch 59 | ), 60 | stop("Unsupported distribution") 61 | ) 62 | 63 | # Update the cache options with the new values and current timestamp. 64 | options( 65 | rJavaEnv.valid_versions_cache = new_versions, 66 | rJavaEnv.valid_versions_timestamp = Sys.time() 67 | ) 68 | 69 | return(new_versions) 70 | } 71 | 72 | #' Get Available Online Versions of Amazon Corretto 73 | #' 74 | #' This function downloads the latest Amazon Corretto version information from the 75 | #' Corretto GitHub endpoint and returns a data frame with details for all eligible releases. 76 | #' 77 | #' It leverages the existing \code{platform_detect()} function to infer the current operating 78 | #' system and architecture if these are not provided. 79 | #' 80 | #' @param arch Optional character string for the target architecture (e.g., "x64"). 81 | #' If \code{NULL}, it is inferred using \code{platform_detect()}. 82 | #' @param platform Optional character string for the operating system (e.g., "windows", "macos", "linux"). 83 | #' If \code{NULL}, it is inferred using \code{platform_detect()}. 84 | #' @param imageType Optional character string to filter on; defaults to \code{"jdk"}. Can be set to \code{"jre"} for Windows Java Runtime Environment. 85 | #' 86 | #' @return A `character` vector of available major Corretto versions. 87 | #' 88 | #' @keywords internal 89 | #' 90 | java_valid_major_versions_corretto <- function( 91 | arch = NULL, 92 | platform = NULL, 93 | imageType = "jdk" 94 | ) { 95 | # If platform or arch are not provided, detect them using the existing function. 96 | if (is.null(platform) || is.null(arch)) { 97 | plat <- platform_detect(quiet = TRUE) 98 | if (is.null(platform)) platform <- plat$os 99 | if (is.null(arch)) arch <- plat$arch 100 | } 101 | 102 | # URL for the Corretto version information. 103 | availableVersionsUrl <- "https://corretto.github.io/corretto-downloads/latest_links/indexmap_with_checksum.json" 104 | 105 | # Fetch and parse the JSON using httr. 106 | corretto_versions <- tryCatch( 107 | { 108 | json_data <- jsonlite::read_json(availableVersionsUrl) 109 | eligible <- json_data[[platform]][[arch]][[imageType]] 110 | if (is.null(eligible)) { 111 | stop( 112 | "No eligible versions found for the specified platform, architecture, and image type." 113 | ) 114 | } 115 | names(eligible) 116 | }, 117 | error = function(e) { 118 | platform_arch <- paste(platform, arch, sep = "_") 119 | getOption(paste0("rJavaEnv.fallback_valid_versions_", platform_arch)) 120 | } 121 | ) 122 | 123 | corretto_versions <- as.character(sort(as.numeric(corretto_versions))) 124 | return(corretto_versions) 125 | } 126 | 127 | # Helper function for Oracle distribution 128 | # java_valid_versions_oracle <- function() { 129 | # oracle_api_url <- "https://java.oraclecloud.com/javaVersions" 130 | # tryCatch( 131 | # { 132 | # oracle_java_versions <- jsonlite::fromJSON( 133 | # oracle_api_url, 134 | # simplifyDataFrame = TRUE 135 | # ) 136 | # # Combine "8" and "11" with the sorted versions from the API 137 | # c("8", "11", sort(as.character(oracle_java_versions$items$jdkVersion))) 138 | # }, 139 | # error = function(e) { 140 | # # If the API call fails, use the fallback list stored in options. 141 | # getOption("rJavaEnv.fallback_valid_versions_current_platform") 142 | # } 143 | # ) 144 | # } 145 | -------------------------------------------------------------------------------- /R/onLoad.R: -------------------------------------------------------------------------------- 1 | .onLoad <- function(libname, pkgname) { 2 | # First, set all the base rJavaEnv options 3 | op <- options() 4 | op.rJavaEnv <- list( 5 | # Default folder choice (in line with renv package) 6 | rJavaEnv.cache_path = tools::R_user_dir("rJavaEnv", which = "cache"), 7 | rJavaEnv.valid_versions_cache = NULL, 8 | rJavaEnv.valid_versions_timestamp = NULL, 9 | # Fallback lists for various platforms 10 | rJavaEnv.fallback_valid_versions_macos_aarch64 = c( 11 | "8", 12 | "11", 13 | "17", 14 | "18", 15 | "19", 16 | "20", 17 | "21", 18 | "22", 19 | "23", 20 | "24" 21 | ), 22 | rJavaEnv.fallback_valid_versions_macos_x64 = c( 23 | "8", 24 | "11", 25 | "15", 26 | "16", 27 | "17", 28 | "18", 29 | "19", 30 | "20", 31 | "21", 32 | "22", 33 | "23", 34 | "24" 35 | ), 36 | rJavaEnv.fallback_valid_versions_linux_aarch64 = c( 37 | "8", 38 | "11", 39 | "15", 40 | "16", 41 | "17", 42 | "18", 43 | "19", 44 | "20", 45 | "21", 46 | "22", 47 | "23", 48 | "24" 49 | ), 50 | rJavaEnv.fallback_valid_versions_linux_x64 = c( 51 | "8", 52 | "11", 53 | "15", 54 | "16", 55 | "17", 56 | "18", 57 | "19", 58 | "20", 59 | "21", 60 | "22", 61 | "23", 62 | "24" 63 | ), 64 | rJavaEnv.fallback_valid_versions_windows_x64 = c( 65 | "8", 66 | "11", 67 | "15", 68 | "16", 69 | "17", 70 | "18", 71 | "19", 72 | "20", 73 | "21", 74 | "22", 75 | "23", 76 | "24" 77 | ), 78 | rJavaEnv.fallback_valid_versions_windows_x86 = c( 79 | "8", 80 | "11" 81 | ) 82 | ) 83 | 84 | # Only set the options that haven't been defined yet 85 | toset <- !(names(op.rJavaEnv) %in% names(op)) 86 | if (any(toset)) options(op.rJavaEnv[toset]) 87 | 88 | # Now, detect the current platform (OS and architecture) 89 | platform <- platform_detect(quiet = TRUE) 90 | 91 | # Build the option name dynamically based on platform$os and platform$arch. 92 | # For example, for macOS on x64, this results in "rJavaEnv.fallback_valid_versions_macos_x64" 93 | fallback_option_name <- paste0( 94 | "rJavaEnv.fallback_valid_versions_", 95 | platform$os, 96 | "_", 97 | platform$arch 98 | ) 99 | 100 | # Retrieve the corresponding fallback list using getOption() 101 | fallback_current <- getOption(fallback_option_name) 102 | 103 | # Set the current platform valid versions option 104 | options(rJavaEnv.fallback_valid_versions_current_platform = fallback_current) 105 | 106 | invisible() 107 | } 108 | -------------------------------------------------------------------------------- /R/rJavaEnv-package.R: -------------------------------------------------------------------------------- 1 | #' @keywords internal 2 | "_PACKAGE" 3 | 4 | ## usethis namespace: start 5 | #' @importFrom utils getFromNamespace 6 | ## usethis namespace: end 7 | NULL 8 | -------------------------------------------------------------------------------- /R/use_java.R: -------------------------------------------------------------------------------- 1 | #' Install specified Java version and set the `JAVA_HOME` and `PATH` environment variables in current R session 2 | #' 3 | #' @description 4 | #' Using specified Java version, set the `JAVA_HOME` and `PATH` environment variables in the current R session. If Java distribtuion has not been downloaded yet, download it. If it was not installed into cache directory yet, install it there and then set the environment variables. This is intended as a quick and easy way to use different Java versions in R scripts that are in the same project, but require different Java versions. For example, one could use this in scripts that are called by `targets` package or `callr` package. 5 | #' @inheritParams java_download 6 | #' @inheritParams java_install 7 | #' @inheritParams global_quiet_param 8 | #' @return `NULL`. Prints the message that Java was set in the current R session if `quiet` is set to `FALSE`. 9 | #' 10 | #' @export 11 | #' 12 | #' @examples 13 | #' \dontrun{ 14 | #' 15 | #' # set cache directory for Java to be in temporary directory 16 | #' options(rJavaEnv.cache_path = tempdir()) 17 | #' 18 | #' # install and set Java 8 in current R session 19 | #' use_java(8) 20 | #' # check Java version 21 | #' "8" == java_check_version_cmd(quiet = TRUE) 22 | #' "8" == java_check_version_rjava(quiet = TRUE) 23 | #' 24 | #' # install and set Java 17 in current R session 25 | #' use_java(17) 26 | #' # check Java version 27 | #' "17" == java_check_version_cmd(quiet = TRUE) 28 | #' "17" == java_check_version_rjava(quiet = TRUE) 29 | #' 30 | #' } 31 | #' 32 | use_java <- function( 33 | version = NULL, 34 | distribution = "Corretto", 35 | cache_path = getOption("rJavaEnv.cache_path"), 36 | platform = platform_detect()$os, 37 | arch = platform_detect()$arch, 38 | quiet = TRUE 39 | ) { 40 | checkmate::check_vector(version, len = 1) 41 | version <- as.character(version) 42 | checkmate::assert_choice(version, java_valid_versions()) 43 | 44 | java_distrib_path <- java_download( 45 | version = version, 46 | distribution = distribution, 47 | cache_path = cache_path, 48 | platform = platform, 49 | arch = arch, 50 | quiet = quiet 51 | ) 52 | 53 | java_cached_install_path <- java_unpack( 54 | java_distrib_path = java_distrib_path, 55 | quiet = quiet 56 | ) 57 | 58 | java_env_set( 59 | where = "session", 60 | java_home = java_cached_install_path, 61 | quiet = quiet 62 | ) 63 | 64 | if (!quiet) { 65 | cli::cli_alert_success( 66 | "Java version {version} was set in the current R session" 67 | ) 68 | } 69 | invisible() 70 | } 71 | -------------------------------------------------------------------------------- /README.qmd: -------------------------------------------------------------------------------- 1 | --- 2 | format: gfm 3 | default-image-extension: "" 4 | --- 5 | 6 | 7 | 8 | ```{r, include = FALSE} 9 | knitr::opts_chunk$set( 10 | collapse = TRUE, 11 | comment = "#>", 12 | fig.path = "man/figures/README-", 13 | out.width = "100%" 14 | ) 15 | 16 | is_html <- knitr::is_html_output() 17 | ``` 18 | 19 | 20 | 21 | # rJavaEnv: Java Environments for R Projects rJavaEnv website 22 | 23 | 24 | 25 | [![Project Status: Active](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) 26 | [![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable){target="_blank"} [![CRAN status](https://www.r-pkg.org/badges/version/rJavaEnv)](https://CRAN.R-project.org/package=rJavaEnv){target="_blank"} 27 | [![CRAN/METACRAN Total downloads](https://cranlogs.r-pkg.org/badges/grand-total/rJavaEnv?color=blue)](https://CRAN.R-project.org/package=rJavaEnv){target="_blank"} 28 | [![CRAN/METACRAN Downloads per month](https://cranlogs.r-pkg.org/badges/rJavaEnv?color=blue)](https://CRAN.R-project.org/package=rJavaEnv){target="_blank"} 29 | [![R-CMD-check](https://github.com/e-kotov/rJavaEnv/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/e-kotov/rJavaEnv/actions/workflows/R-CMD-check.yaml) 30 | 31 | [![codecov](https://codecov.io/github/e-kotov/rJavaEnv/graph/badge.svg?token=2UKGZVNO5V)](https://app.codecov.io/github/e-kotov/rJavaEnv) 32 | 33 | [![DOI](https://zenodo.org/badge/DOI/10.32614/CRAN.package.rJavaEnv.svg)](https://doi.org/10.32614/CRAN.package.rJavaEnv) 34 | [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.11403009.svg)](https://doi.org/10.5281/zenodo.11403009) 35 | 36 | 37 | 38 | Quickly install `Java Development Kit (JDK)` without administrative privileges and set environment variables in current R session or project to solve common issues with 'Java' environment management in 'R'. Recommended to users of `Java`/`{rJava}`-dependent `R` packages such as `{r5r}`, `{opentripplanner}`, `{xlsx}`, `{openNLP}`, `{rWeka}`, `{RJDBC}`, `{tabulapdf}`, and many more. `{rJavaEnv}` prevents common problems like `Java` not found, `Java` version conflicts, missing `Java` installations, and the inability to install `Java` due to lack of administrative privileges. `{rJavaEnv}` automates the download, installation, and setup of the `Java` on a per-project basis by setting the relevant `JAVA_HOME` in the current `R` session or the current working directory (via `.Rprofile`, with the user's consent). Similar to what `{renv}` does for `R` packages, `{rJavaEnv}` allows different `Java` versions to be used across different projects, but can also be configured to allow multiple versions within the same project (e.g. with the help of `{targets}` package). **Note: there are a few extra steps for 'Linux' users, who don't have any 'Java' previously installed in their system, and who prefer package installation from source, rather then installing binaries from 'Posit Package Manager'. See [documentation](https://www.ekotov.pro/rJavaEnv/articles/rJavaEnv.html#note-linux) for details.** 39 | 40 | 41 | 42 | 43 | ```{r results="asis", eval = !is_html, include = !is_html, include = FALSE} 44 | glue::glue( 45 | '' 48 | ) 49 | ``` 50 | 51 | ## Install 52 | 53 | Install from CRAN: 54 | 55 | ```r 56 | install.packages('rJavaEnv') 57 | ``` 58 | 59 | 60 |
61 | 62 | 63 | Install the development version 64 | 65 | 66 | Install the latest release development version from **R-multiverse**: 67 | 68 | ```r 69 | install.packages('rJavaEnv', 70 | repos = c('https://community.r-multiverse.org', 'https://cloud.r-project.org') 71 | ) 72 | ``` 73 | 74 | You can also install the development version of `rJavaEnv` directly from GitHub: 75 | 76 | ```r 77 | if (!requireNamespace("remotes", quietly = TRUE)) { 78 | install.packages("remotes") 79 | } 80 | 81 | remotes::install_github("e-kotov/rJavaEnv", force = TRUE) 82 | ``` 83 | 84 |
85 | 86 | ## Simple Example 87 | 88 | ```r 89 | rJavaEnv::java_quick_install(version = 21) 90 | ``` 91 | 92 | This will: 93 | 94 | - download `Java` 21 distribution compatible with the current operating system and processor architecture into a local cache folder; 95 | 96 | - extract the downloaded `Java` distribution into another cache folder; 97 | 98 | - create a symbolic link (for macOS and Linux) or junction (for Windows, if that fails, just copies the files) **rjavaenv/`platform`/`processor_architecture`/`java_version`** in the current directory/project to point to the cached installation; 99 | 100 | - set the current session's `JAVA_HOME` and `PATH` environment variables to point to the installed (symlinked) `Java` distribution; 101 | 102 | - add code to `.Rprofile` file in the current directory/project to set `JAVA_HOME` and `PATH` environment variables when the project is opened in RStudio. 103 | 104 | 105 | As part of normal operation, `rJavaEnv` will update the `JAVA_HOME` and `PATH` environment variables in the current R session, the local cache in your R package library, and the `.Rprofile` file in the project/current working directory. In line with [CRAN policies](https://cran.r-project.org/web/packages/policies.html), explicit user consent is required before making these changes. Therefore, the first time you run any function from `rJavaEnv` that makes such changes, you will be asked for consent. To explicitly consent and/or to prevent interruptions in non-interactive mode, you can use the `rje_consent()` function: 106 | 107 | ```r 108 | rje_consent(provided = TRUE) 109 | ``` 110 | 111 | ## Using `rJavaEnv` with `targets` and `callr` 112 | 113 | Just insert this line into the begining of any script that you run with `targets` or `callr`: 114 | 115 | ```r 116 | rJavaEnv::use_java("21") 117 | ``` 118 | 119 | This acts exactly like `java_quick_install()`, but only sets the environment variables in the current session and does not copy or link `Java` binaries into the project directory. 120 | 121 | More details are in the vignette [Multiple `Java` environments in one project with `targets` and `callr`](https://www.ekotov.pro/rJavaEnv/articles/multiple-java-with-targets-callr.html). 122 | 123 | ## Cleanup 124 | 125 | If you do not want to use `rJavaEnv` anymore, please clear the cache folders before removing the package: 126 | 127 | ```r 128 | java_clear("project", delete_all = TRUE) 129 | java_clear("installed", delete_all = TRUE) 130 | java_clear("distrib", delete_all = TRUE) 131 | ``` 132 | 133 | Also, clear the `.Rprofile` file in the projects there you used the package: 134 | 135 | ```r 136 | java_env_unset() 137 | ``` 138 | 139 | ## Functions Overview 140 | 141 | The package has several core functions: 142 | 143 | 1. `java_quick_install()` 144 | * Downloads, installs, and sets Java environment in the current working/project directory, all in one line of code. 145 | 146 | 2. `java_check_version_cmd()` 147 | * Checks the installed Java version using terminal commands. For packages like [`opentripplanner`](https://github.com/ropensci/opentripplanner){target="_blank"}, that performs Java calls using command line. 148 | 149 | 3. `java_version_check_rjava()` 150 | * Checks the installed `Java` version using `rJava` in a separate R session. For `rJava`-dependent packages such as [`r5r`](https://github.com/ipeaGIT/r5r){target="_blank"}. 151 | 152 | 4. `java_download()` 153 | * Downloads a specified version and distribution of `Java`. 154 | 155 | 5. `java_install()` 156 | * Installs a `Java` distribution file into current (or user-specified) project directory. 157 | 158 | 6. `java_env_set()` 159 | * Sets the `JAVA_HOME` and `PATH` environment variables to a given path in current R session and/or in the `.Rprofile` file in the project directory. 160 | 161 | 7. `java_env_unset()` 162 | * Remove the `JAVA_HOME` and `PATH` environment variables from the `.Rrpofile` file in the project directory (but not in the current R session, please restart the session so that R picks up the system Java). 163 | 164 | 8. `java_list()` 165 | * Lists all or some `Java` versions linked in the current project (or cached distributions or installations). 166 | 167 | 9. `java_clear()` 168 | * Removes all or some `Java` versions linked in the current project (or cached distributions or installations). 169 | 170 | 10 `java_valid_versions()` 171 | * Lists all valid major `Java` versions that can be downloaded and installed for either current automatically detected OS and CPU architecture or user-specified platform and architecture. 172 | 173 | 11. `use_java()` 174 | * Same as `java_quick_install()`, but in a less intrusive way. Does not copy or link the `Java` installation folder from cache into the project directory and does not create or edit your `.Rprofile` file. Only sets requested java in the current R session. 175 | 176 | See more details on all the functions in the [Reference](https://www.ekotov.pro/rJavaEnv/reference/index.html){target="_blank"}. 177 | 178 | 179 | For detailed usage, see the [Quick Start Vignette](https://www.ekotov.pro/rJavaEnv/articles/rJavaEnv.html) (work in progress). 180 | 181 | ## Limitations 182 | 183 | Currently, `rJavaEnv` only supports major `Java` versions such as 8, 11, 15 to 24 and any newer version. The download and install functions ignore the minor version of the `Java` distribution and just downloads the latest stable subversion of the specified major version. This is done to simplify the process and avoid the need to update the package every time a new minor version of `Java` is released. For most users this should be sufficient, but this is substandard for full reproducibility. 184 | 185 | The main limitation is that if you want to switch to another `Java` environment, you will most likely have to restart the current R session and set the `JAVA_HOME` and `PATH` environment variables to the desired `Java` environment using `rJavaEnv::java_env_set()`. This cannot be done dynamically within the same R session due to the way Java is initialized in R, particularly with the `rJava`-dependent packages such as [`r5r`](https://github.com/ipeaGIT/r5r){target="_blank"}. With packages like [`opentripplanner`](https://github.com/ropensci/opentripplanner){target="_blank"}, that performs `Java` calls using command line, you can switch `Java` environments dynamically within the same R session as much as you want. 186 | 187 | Therefore, if you need to use R packages that depend on different `Java` versions within the same project, you will have to create separate R scripts for each `Java` environment and run them in separate R sessions. One effective way of doing this is to use the [`callr`](https://github.com/r-lib/callr){target="_blank"} package to run R scripts in separate R sessions. Another option is to use the [`targets`](https://github.com/ropensci/targets){target="_blank"} package to manage the whole project workflow, which, as a side effect, will lead to all R scripts being run in separate R sessions. To use `rJavaEnv` with `targets`, you will need to download and install several Java environments using `rJavaEnv::java_download()` and `rJavaEnv::java_install()` and set the relevant path with `rJavaEnv::java_env_set()` at the beginning of each function that requires a certain `Java` version. 188 | 189 | ## Future work 190 | 191 | The future work includes: 192 | 193 | - Add support for more `Java` distributions and versions 194 | 195 | - Take care of [`R CMD javareconf`](https://solutions.posit.co/envs-pkgs/using-rjava/#reconfigure-r){target="_blank"} 196 | 197 | - Possibly add support for specifying `Java` version beyond the major version 198 | 199 | - Possibly allow downloading several `Java` distributions in one function call, e.g. different major versions of the same 'flavour' or different 'flavours' of the same major version 200 | 201 | - Possibly add automation to get the `Java` that is required by specific `Java`-dependent R packages 202 | 203 | I am open to suggestions and contributions, welcome to [issues](https://github.com/e-kotov/rJavaEnv/issues){target="_blank"} and [pull requests](https://github.com/e-kotov/rJavaEnv/pulls){target="_blank"}. 204 | 205 | 206 | ## Acknowledgements 207 | 208 | I thank rOpenSci for the [Dev Guide](https://devguide.ropensci.org/){target="_blank"}, as well as Hadley Wickham and Jennifer Bryan for the [R Packages](https://r-pkgs.org/){target="_blank"} book. 209 | 210 | Package hex sticker logo is partially generated by DALL-E by OpenAI. The logo also contains the original R logo. 211 | 212 | ## Citation 213 | 214 | ```{r echo=FALSE, results='asis'} 215 | print(citation("rJavaEnv"), bibtex = FALSE) 216 | ``` 217 | 218 | BibTeX: 219 | ``` 220 | ```{r echo=FALSE, results='asis'} 221 | toBibtex(citation("rJavaEnv")) 222 | ``` 223 | ``` 224 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | url: https://www.ekotov.pro/rJavaEnv/ 2 | template: 3 | bootstrap: 5 4 | bootswatch: flatly 5 | includes: 6 | in_header: | 7 | 8 | 9 | 10 | 11 | 21 | opengraph: 22 | image: 23 | src: man/figures/card.png 24 | alt: "rJavaEnv: Java Environments for R Projects. Install and manage Java environments using R" 25 | twitter: 26 | creator: "@EgorKotov" 27 | card: summary_large_image 28 | 29 | authors: 30 | Egor Kotov: 31 | href: "https://www.ekotov.pro" 32 | 33 | navbar: 34 | structure: 35 | left: [intro, reference, articles, tutorials, news] 36 | right: [search, github, lightswitch] 37 | 38 | home: 39 | title: 'rJavaEnv: `Java` Environments for R Projects' 40 | description: 'Install and manage `Java` environments using R' 41 | 42 | 43 | reference: 44 | - title: "Quick Install" 45 | desc: > 46 | Just quickly install `Java` in the current project 47 | contents: 48 | - java_quick_install 49 | - title: "Quick Set" 50 | desc: > 51 | Just quickly set `Java` in the current project (for use with `targets`/`callr`) 52 | contents: 53 | - use_java 54 | - title: "Check `Java` version" 55 | desc: > 56 | Check `Java` version with currently set environment 57 | contents: 58 | - java_check_version_cmd 59 | - java_check_version_rjava 60 | - title: "Fine-grained Control" 61 | desc: > 62 | Control every step of `Java` download, unpacking and installation 63 | contents: 64 | - java_download 65 | - java_unpack 66 | - java_install 67 | - java_env_set 68 | - java_env_unset 69 | - title: "Manage files" 70 | desc: > 71 | Manage downloads, installs, and project-linked `Java` versions 72 | contents: 73 | - java_list 74 | - java_clear 75 | - title: "Other commands" 76 | contents: 77 | - java_valid_versions 78 | - rje_consent 79 | 80 | 81 | 82 | articles: 83 | - title: Documentation 84 | navbar: ~ 85 | contents: 86 | - rJavaEnv-step-by-step 87 | - multiple-java-with-targets-callr 88 | - why-rJavaEnv 89 | -------------------------------------------------------------------------------- /codemeta.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": "https://doi.org/10.5063/schema/codemeta-2.0", 3 | "@type": "SoftwareSourceCode", 4 | "identifier": "rJavaEnv", 5 | "description": "Quickly install 'Java Development Kit (JDK)' without administrative privileges and set environment variables in current R session or project to solve common issues with 'Java' environment management in 'R'. Recommended to users of 'Java'/'rJava'-dependent 'R' packages such as 'r5r', 'opentripplanner', 'xlsx', 'openNLP', 'rWeka', 'RJDBC', 'tabulapdf', and many more. 'rJavaEnv' prevents common problems like 'Java' not found, 'Java' version conflicts, missing 'Java' installations, and the inability to install 'Java' due to lack of administrative privileges. 'rJavaEnv' automates the download, installation, and setup of the 'Java' on a per-project basis by setting the relevant 'JAVA_HOME' in the current 'R' session or the current working directory (via '.Rprofile', with the user's consent). Similar to what 'renv' does for 'R' packages, 'rJavaEnv' allows different 'Java' versions to be used across different projects, but can also be configured to allow multiple versions within the same project (e.g. with the help of 'targets' package). Note: there are a few extra steps for 'Linux' users, who don't have any 'Java' previously installed in their system, and who prefer package installation from source, rather then installing binaries from 'Posit Package Manager'. See documentation for details.", 6 | "name": "rJavaEnv: 'Java' Environments for R Projects", 7 | "relatedLink": "https://www.ekotov.pro/rJavaEnv/", 8 | "codeRepository": "https://github.com/e-kotov/rJavaEnv", 9 | "issueTracker": "https://github.com/e-kotov/rJavaEnv/issues", 10 | "license": "https://spdx.org/licenses/MIT", 11 | "version": "0.3.0", 12 | "programmingLanguage": { 13 | "@type": "ComputerLanguage", 14 | "name": "R", 15 | "url": "https://r-project.org" 16 | }, 17 | "runtimePlatform": "R version 4.4.3 (2025-02-28)", 18 | "provider": { 19 | "@id": "https://cran.r-project.org", 20 | "@type": "Organization", 21 | "name": "Comprehensive R Archive Network (CRAN)", 22 | "url": "https://cran.r-project.org" 23 | }, 24 | "author": [ 25 | { 26 | "@type": "Person", 27 | "givenName": "Egor", 28 | "familyName": "Kotov", 29 | "email": "kotov.egor@gmail.com", 30 | "@id": "https://orcid.org/0000-0001-6690-5345" 31 | }, 32 | { 33 | "@type": "Person", 34 | "givenName": "Chung-hong", 35 | "familyName": "Chan", 36 | "email": "chainsawtiney@gmail.com", 37 | "@id": "https://orcid.org/0000-0002-6232-7530" 38 | } 39 | ], 40 | "contributor": [ 41 | { 42 | "@type": "Person", 43 | "givenName": "Mauricio", 44 | "familyName": "Vargas", 45 | "email": "mavargas11@uc.cl", 46 | "@id": "https://orcid.org/0000-0003-1017-7574" 47 | }, 48 | { 49 | "@type": "Person", 50 | "givenName": "Hadley", 51 | "familyName": "Wickham", 52 | "email": "hadley@posit.co" 53 | }, 54 | { 55 | "@type": "Person", 56 | "givenName": "Enrique", 57 | "familyName": "Mondragon-Estrada", 58 | "email": "enriquemondragon@proton.me", 59 | "@id": "https://orcid.org/0009-0004-5592-1728" 60 | }, 61 | { 62 | "@type": "Person", 63 | "givenName": "Jonas", 64 | "familyName": "Lieth", 65 | "email": "jonas.lieth@gesis.org", 66 | "@id": "https://orcid.org/0000-0002-3451-3176" 67 | } 68 | ], 69 | "copyrightHolder": [ 70 | { 71 | "@type": "Person", 72 | "givenName": "Egor", 73 | "familyName": "Kotov", 74 | "email": "kotov.egor@gmail.com", 75 | "@id": "https://orcid.org/0000-0001-6690-5345" 76 | } 77 | ], 78 | "maintainer": [ 79 | { 80 | "@type": "Person", 81 | "givenName": "Egor", 82 | "familyName": "Kotov", 83 | "email": "kotov.egor@gmail.com", 84 | "@id": "https://orcid.org/0000-0001-6690-5345" 85 | } 86 | ], 87 | "softwareSuggestions": [ 88 | { 89 | "@type": "SoftwareApplication", 90 | "identifier": "quarto", 91 | "name": "quarto", 92 | "provider": { 93 | "@id": "https://cran.r-project.org", 94 | "@type": "Organization", 95 | "name": "Comprehensive R Archive Network (CRAN)", 96 | "url": "https://cran.r-project.org" 97 | }, 98 | "sameAs": "https://CRAN.R-project.org/package=quarto" 99 | }, 100 | { 101 | "@type": "SoftwareApplication", 102 | "identifier": "rJava", 103 | "name": "rJava", 104 | "provider": { 105 | "@id": "https://cran.r-project.org", 106 | "@type": "Organization", 107 | "name": "Comprehensive R Archive Network (CRAN)", 108 | "url": "https://cran.r-project.org" 109 | }, 110 | "sameAs": "https://CRAN.R-project.org/package=rJava" 111 | }, 112 | { 113 | "@type": "SoftwareApplication", 114 | "identifier": "testthat", 115 | "name": "testthat", 116 | "version": ">= 3.0.0", 117 | "provider": { 118 | "@id": "https://cran.r-project.org", 119 | "@type": "Organization", 120 | "name": "Comprehensive R Archive Network (CRAN)", 121 | "url": "https://cran.r-project.org" 122 | }, 123 | "sameAs": "https://CRAN.R-project.org/package=testthat" 124 | } 125 | ], 126 | "softwareRequirements": { 127 | "1": { 128 | "@type": "SoftwareApplication", 129 | "identifier": "R", 130 | "name": "R", 131 | "version": ">= 4.0" 132 | }, 133 | "2": { 134 | "@type": "SoftwareApplication", 135 | "identifier": "checkmate", 136 | "name": "checkmate", 137 | "provider": { 138 | "@id": "https://cran.r-project.org", 139 | "@type": "Organization", 140 | "name": "Comprehensive R Archive Network (CRAN)", 141 | "url": "https://cran.r-project.org" 142 | }, 143 | "sameAs": "https://CRAN.R-project.org/package=checkmate" 144 | }, 145 | "3": { 146 | "@type": "SoftwareApplication", 147 | "identifier": "cli", 148 | "name": "cli", 149 | "provider": { 150 | "@id": "https://cran.r-project.org", 151 | "@type": "Organization", 152 | "name": "Comprehensive R Archive Network (CRAN)", 153 | "url": "https://cran.r-project.org" 154 | }, 155 | "sameAs": "https://CRAN.R-project.org/package=cli" 156 | }, 157 | "4": { 158 | "@type": "SoftwareApplication", 159 | "identifier": "curl", 160 | "name": "curl", 161 | "provider": { 162 | "@id": "https://cran.r-project.org", 163 | "@type": "Organization", 164 | "name": "Comprehensive R Archive Network (CRAN)", 165 | "url": "https://cran.r-project.org" 166 | }, 167 | "sameAs": "https://CRAN.R-project.org/package=curl" 168 | }, 169 | "5": { 170 | "@type": "SoftwareApplication", 171 | "identifier": "jsonlite", 172 | "name": "jsonlite", 173 | "provider": { 174 | "@id": "https://cran.r-project.org", 175 | "@type": "Organization", 176 | "name": "Comprehensive R Archive Network (CRAN)", 177 | "url": "https://cran.r-project.org" 178 | }, 179 | "sameAs": "https://CRAN.R-project.org/package=jsonlite" 180 | }, 181 | "6": { 182 | "@type": "SoftwareApplication", 183 | "identifier": "utils", 184 | "name": "utils" 185 | }, 186 | "SystemRequirements": null 187 | }, 188 | "fileSize": "351786.753KB", 189 | "citation": [ 190 | { 191 | "@type": "SoftwareSourceCode", 192 | "datePublished": "2024", 193 | "author": [ 194 | { 195 | "@type": "Person", 196 | "givenName": "Egor", 197 | "familyName": "Kotov", 198 | "email": "kotov.egor@gmail.com", 199 | "@id": "https://orcid.org/0000-0001-6690-5345" 200 | }, 201 | { 202 | "@type": "Person", 203 | "givenName": "Chung-hong", 204 | "familyName": "Chan", 205 | "email": "chainsawtiney@gmail.com", 206 | "@id": "https://orcid.org/0000-0002-6232-7530" 207 | } 208 | ], 209 | "name": "rJavaEnv: Java Environments for R Projects", 210 | "identifier": "10.32614/CRAN.package.rJavaEnv", 211 | "url": "https://github.com/e-kotov/rJavaEnv", 212 | "@id": "https://doi.org/10.32614/CRAN.package.rJavaEnv", 213 | "sameAs": "https://doi.org/10.32614/CRAN.package.rJavaEnv" 214 | } 215 | ], 216 | "releaseNotes": "https://github.com/e-kotov/rJavaEnv/blob/master/NEWS.md", 217 | "readme": "https://github.com/e-kotov/rJavaEnv/blob/main/README.md", 218 | "contIntegration": ["https://github.com/e-kotov/rJavaEnv/actions/workflows/R-CMD-check.yaml", "https://app.codecov.io/github/e-kotov/rJavaEnv"], 219 | "developmentStatus": "https://www.repostatus.org/#active", 220 | "keywords": ["environments", "java", "r", "reproducibility", "reproducible-research"] 221 | } 222 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | # rJavaEnv 0.3.0 (2025-04-04) 2 | 3 | 4 | ## New features 5 | 6 | - `Java` version (currently still only for `Amazon Corretto`) is now determined dynamically using the official GitHub `json` with releases, so when new `Java` version becomes available, you will not be depenent on `rJavaEnv` to be updated. As a fallback, versions up to 24 are hardcoded. 7 | 8 | - Added `force` argument to `java_download()`. When set to `TRUE`, allows to overwrite the distribution file if it already exist in the cache. This save the trouble of deleting the cached file with `java_clear()` before re-downloading. 9 | 10 | - Added a new function `java_valid_versions()` allows to retrieve a list of all available `Java` versions for the current automatically detected OS and CPU architecture, or user-specified platform and architecture. 11 | 12 | ## Improvements 13 | 14 | - Better command line `Java` detection (thanks to Jonas Lieth) 15 | 16 | - Test coverage is now 7.2% 17 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | bibentry( 2 | key = "rjavaenv", 3 | bibtype = "Manual", 4 | title = "rJavaEnv: Java Environments for R Projects", 5 | author = c( 6 | person("Egor", "Kotov", , "kotov.egor@gmail.com", role = c("aut", "cre", "cph"), 7 | comment = c(ORCID = "0000-0001-6690-5345")), 8 | person("Chung-hong", "Chan", , "chainsawtiney@gmail.com", role = "aut", 9 | comment = c(ORCID = "0000-0002-6232-7530")) 10 | ), 11 | year = "2024", 12 | url = "https://github.com/e-kotov/rJavaEnv", 13 | doi = "10.32614/CRAN.package.rJavaEnv" 14 | ) 15 | -------------------------------------------------------------------------------- /inst/extdata/java_urls.json: -------------------------------------------------------------------------------- 1 | { 2 | "Corretto": { 3 | "windows": { 4 | "x64": "https://corretto.aws/downloads/latest/amazon-corretto-{version}-x64-windows-jdk.zip" 5 | }, 6 | "linux": { 7 | "x64": "https://corretto.aws/downloads/latest/amazon-corretto-{version}-x64-linux-jdk.tar.gz", 8 | "aarch64": "https://corretto.aws/downloads/latest/amazon-corretto-{version}-aarch64-linux-jdk.tar.gz" 9 | }, 10 | "macos": { 11 | "x64": "https://corretto.aws/downloads/latest/amazon-corretto-{version}-x64-macos-jdk.tar.gz", 12 | "aarch64": "https://corretto.aws/downloads/latest/amazon-corretto-{version}-aarch64-macos-jdk.tar.gz" 13 | }, 14 | "alpine-linux": { 15 | "x64": "https://corretto.aws/downloads/latest/amazon-corretto-{version}-x64-alpine-jdk.tar.gz", 16 | "aarch64": "https://corretto.aws/downloads/latest/amazon-corretto-{version}-aarch64-alpine-jdk.tar.gz" 17 | }, 18 | "amazon-linux": { 19 | "x64": "https://corretto.aws/downloads/latest/amazon-corretto-{version}-x64-al2-jdk.rpm", 20 | "aarch64": "https://corretto.aws/downloads/latest/amazon-corretto-{version}-aarch64-al2-jdk.rpm" 21 | }, 22 | "amazon-linux-2023": { 23 | "x64": "https://corretto.aws/downloads/latest/amazon-corretto-{version}-x64-al2023-jdk.rpm", 24 | "aarch64": "https://corretto.aws/downloads/latest/amazon-corretto-{version}-aarch64-al2023-jdk.rpm" 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /inst/resources/consent-info: -------------------------------------------------------------------------------- 1 | `rJavaEnv`: Manage Java Environments for R Projects 2 | 3 | Welcome to `rJavaEnv`! It looks like this is your first time using `rJavaEnv`. 4 | This message will guide you through some of the key features and how `rJavaEnv` works. 5 | 6 | `rJavaEnv` will manage Java Development Kits (JDKs) specifically for your R projects, 7 | ensuring that each project uses the appropriate Java version 8 | without affecting other projects or your system-wide Java installation. 9 | 10 | Here's what `rJavaEnv` will do: 11 | 12 | - Create a 'rjavaenv' folder in your project/current working directory. 13 | - Generate necessary configuration files in the project/current working directory. 14 | - Update your $JAVA_HOME and $PATH variables within the current R session. 15 | 16 | `rJavaEnv` will also update some existing files in your project/current working directory, such as: 17 | 18 | - .Rprofile 19 | 20 | Additionally, `rJavaEnv` maintains a cache of Java distributions and installations at: 21 | 22 | - ${rJavaEnv_CACHE} 23 | 24 | You can customize this path by setting the option `options(rJavaEnv.cache_path = 'path/to/your/java/cache')`. 25 | Alternatively, you can set the cache folder as argument `cache_path` package functions that have option. 26 | The same cache folder is used for both zipped java distributions and extracted distribution files. 27 | 28 | For more information, read the introductory vignette with `vignette("rJavaEnv")` and browse the package documentation online at https://www.ekotov.pro/rJavaEnv/. 29 | 30 | Whenever you install any `Java` JDK, kindly read the respective software license and agree to it before use. 31 | For the current default JDK installed with rJavaEnv, which is Amazon Corretto, please find the license for the version 32 | you are installing at https://github.com/corretto/. 33 | 34 | Finally, if you are on a Linux system that did not have any 'Java' version previoulsy installed and you are not using pre-build 'R' package binaries (for example from 'Posit Package Manager') and instead install all 'R' packages from source, after this step you may have to quit R, follow these steps: https://solutions.posit.co/envs-pkgs/using-rjava/#reconfigure-r to set configure 'Java' for 'R', and only then install 'rJava', as otherwise 'rJava' cannot be built from source. 35 | -------------------------------------------------------------------------------- /inst/schemaorg.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": "https://schema.org", 3 | "@graph": [ 4 | { 5 | "type": "SoftwareSourceCode", 6 | "author": [ 7 | { 8 | "id": "https://orcid.org/0000-0002-6232-7530", 9 | "type": "Person", 10 | "email": "chainsawtiney@gmail.com", 11 | "familyName": "Chan", 12 | "givenName": "Chung-hong" 13 | }, 14 | { 15 | "id": "https://orcid.org/0000-0001-6690-5345" 16 | } 17 | ], 18 | "codeRepository": "https://github.com/e-kotov/rJavaEnv", 19 | "contributor": [ 20 | { 21 | "id": "https://orcid.org/0000-0003-1017-7574", 22 | "type": "Person", 23 | "email": "mavargas11@uc.cl", 24 | "familyName": "Vargas", 25 | "givenName": "Mauricio" 26 | }, 27 | { 28 | "type": "Person", 29 | "email": "hadley@posit.co", 30 | "familyName": "Wickham", 31 | "givenName": "Hadley" 32 | }, 33 | { 34 | "id": "https://orcid.org/0009-0004-5592-1728", 35 | "type": "Person", 36 | "email": "enriquemondragon@proton.me", 37 | "familyName": "Mondragon-Estrada", 38 | "givenName": "Enrique" 39 | }, 40 | { 41 | "id": "https://orcid.org/0000-0002-3451-3176", 42 | "type": "Person", 43 | "email": "jonas.lieth@gesis.org", 44 | "familyName": "Lieth", 45 | "givenName": "Jonas" 46 | } 47 | ], 48 | "copyrightHolder": { 49 | "id": "https://orcid.org/0000-0001-6690-5345", 50 | "type": "Person", 51 | "email": "kotov.egor@gmail.com", 52 | "familyName": "Kotov", 53 | "givenName": "Egor" 54 | }, 55 | "description": "Quickly install 'Java Development Kit (JDK)' without administrative privileges and set environment variables in current R session or project to solve common issues with 'Java' environment management in 'R'. Recommended to users of 'Java'/'rJava'-dependent 'R' packages such as 'r5r', 'opentripplanner', 'xlsx', 'openNLP', 'rWeka', 'RJDBC', 'tabulapdf', and many more. 'rJavaEnv' prevents common problems like 'Java' not found, 'Java' version conflicts, missing 'Java' installations, and the inability to install 'Java' due to lack of administrative privileges. 'rJavaEnv' automates the download, installation, and setup of the 'Java' on a per-project basis by setting the relevant 'JAVA_HOME' in the current 'R' session or the current working directory (via '.Rprofile', with the user's consent). Similar to what 'renv' does for 'R' packages, 'rJavaEnv' allows different 'Java' versions to be used across different projects, but can also be configured to allow multiple versions within the same project (e.g. with the help of 'targets' package). Note: there are a few extra steps for 'Linux' users, who don't have any 'Java' previously installed in their system, and who prefer package installation from source, rather then installing binaries from 'Posit Package Manager'. See documentation for details.", 56 | "license": "https://spdx.org/licenses/MIT", 57 | "name": "rJavaEnv: 'Java' Environments for R Projects", 58 | "programmingLanguage": { 59 | "type": "ComputerLanguage", 60 | "name": "R", 61 | "url": "https://r-project.org" 62 | }, 63 | "provider": { 64 | "id": "https://cran.r-project.org", 65 | "type": "Organization", 66 | "name": "Comprehensive R Archive Network (CRAN)", 67 | "url": "https://cran.r-project.org" 68 | }, 69 | "runtimePlatform": "R version 4.4.3 (2025-02-28)", 70 | "version": "0.3.0" 71 | }, 72 | { 73 | "id": "https://doi.org/10.32614/CRAN.package.rJavaEnv", 74 | "type": "SoftwareSourceCode", 75 | "author": [ 76 | { 77 | "id": "https://orcid.org/0000-0001-6690-5345", 78 | "type": "Person", 79 | "email": "kotov.egor@gmail.com", 80 | "familyName": "Kotov", 81 | "givenName": "Egor" 82 | }, 83 | { 84 | "id": "https://orcid.org/0000-0002-6232-7530", 85 | "type": "Person", 86 | "email": "chainsawtiney@gmail.com", 87 | "familyName": "Chan", 88 | "givenName": "Chung-hong" 89 | } 90 | ], 91 | "name": "rJavaEnv: Java Environments for R Projects" 92 | } 93 | ] 94 | } 95 | -------------------------------------------------------------------------------- /man/figures/card.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-kotov/rJavaEnv/c92d57937daee003b04d132441e0824250a29e4a/man/figures/card.png -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-kotov/rJavaEnv/c92d57937daee003b04d132441e0824250a29e4a/man/figures/logo.png -------------------------------------------------------------------------------- /man/global_quiet_param.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/global_params.R 3 | \name{global_quiet_param} 4 | \alias{global_quiet_param} 5 | \title{Global Quiet Parameter} 6 | \usage{ 7 | global_quiet_param(quiet) 8 | } 9 | \arguments{ 10 | \item{quiet}{A \code{logical} value indicating whether to suppress messages. Can be \code{TRUE} or \code{FALSE}.} 11 | } 12 | \description{ 13 | Documentation for the \code{quiet} parameter, used globally. 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/java_check_version_cmd.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_env.R 3 | \name{java_check_version_cmd} 4 | \alias{java_check_version_cmd} 5 | \title{Check installed Java version using terminal commands} 6 | \usage{ 7 | java_check_version_cmd(java_home = NULL, quiet = FALSE) 8 | } 9 | \arguments{ 10 | \item{java_home}{Path to Java home directory. If NULL, the function uses the JAVA_HOME environment variable.} 11 | 12 | \item{quiet}{A \code{logical} value indicating whether to suppress messages. Can be \code{TRUE} or \code{FALSE}.} 13 | } 14 | \value{ 15 | A \code{character} vector of length 1 containing the major Java version. 16 | } 17 | \description{ 18 | Check installed Java version using terminal commands 19 | } 20 | \examples{ 21 | java_check_version_cmd() 22 | 23 | } 24 | -------------------------------------------------------------------------------- /man/java_check_version_rjava.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_env.R 3 | \name{java_check_version_rjava} 4 | \alias{java_check_version_rjava} 5 | \title{Check Java Version with a Specified JAVA_HOME Using a Separate R Session} 6 | \usage{ 7 | java_check_version_rjava(java_home = NULL, quiet = FALSE) 8 | } 9 | \arguments{ 10 | \item{java_home}{Path to Java home directory. If NULL, the function uses the JAVA_HOME environment variable.} 11 | 12 | \item{quiet}{A \code{logical} value indicating whether to suppress messages. Can be \code{TRUE} or \code{FALSE}.} 13 | } 14 | \value{ 15 | A \code{character} vector of length 1 containing the major Java version. 16 | } 17 | \description{ 18 | This function sets the JAVA_HOME environment variable, initializes the JVM using rJava, and prints the Java version that would be used if the user sets the given JAVA_HOME in the current R session. This check is performed in a separate R session to avoid having to reload the current R session. The reason for this is that once Java is initialized in an R session, it cannot be uninitialized unless the current R session is restarted. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | java_check_version_rjava() 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/java_check_version_system.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_env.R 3 | \name{java_check_version_system} 4 | \alias{java_check_version_system} 5 | \title{Check and print Java path and version using system commands} 6 | \usage{ 7 | java_check_version_system(quiet) 8 | } 9 | \arguments{ 10 | \item{quiet}{A \code{logical} value indicating whether to suppress messages. Can be \code{TRUE} or \code{FALSE}.} 11 | } 12 | \value{ 13 | A \code{character} vector of length 1 containing the major Java version. 14 | } 15 | \description{ 16 | This function checks the Java executable path and retrieves the Java version, 17 | then prints these details to the console. 18 | } 19 | \keyword{internal} 20 | -------------------------------------------------------------------------------- /man/java_clear.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_manage.R 3 | \name{java_clear} 4 | \alias{java_clear} 5 | \title{Manage Java installations and distributions caches} 6 | \usage{ 7 | java_clear( 8 | type = c("project", "installed", "distrib"), 9 | target_dir = NULL, 10 | check = TRUE, 11 | delete_all = FALSE 12 | ) 13 | } 14 | \arguments{ 15 | \item{type}{What to clear: "project" - remove symlinks to install cache in the current project, "installed" - remove installed Java versions, "distrib" - remove downloaded Java distributions.} 16 | 17 | \item{target_dir}{The directory to clear. Defaults to current working directory for "project" and user-specific data directory for "installed" and "distrib". Not recommended to change.} 18 | 19 | \item{check}{Whether to list the contents of the cache directory before clearing it. Defaults to TRUE.} 20 | 21 | \item{delete_all}{Whether to delete all items without prompting. Defaults to FALSE.} 22 | } 23 | \value{ 24 | A message indicating whether the cache was cleared or not. 25 | } 26 | \description{ 27 | Wrapper function to clear the Java symlinked in the current project, installed, or distributions caches. 28 | } 29 | \examples{ 30 | \dontrun{ 31 | java_clear("project", target_dir = tempdir()) 32 | java_clear("installed", target_dir = tempdir()) 33 | java_clear("distrib", target_dir = tempdir()) 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /man/java_clear_distrib_cache.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_manage_distrib_cache.R 3 | \name{java_clear_distrib_cache} 4 | \alias{java_clear_distrib_cache} 5 | \title{Clear the Java distributions cache folder} 6 | \usage{ 7 | java_clear_distrib_cache( 8 | cache_path = getOption("rJavaEnv.cache_path"), 9 | check = TRUE, 10 | delete_all = FALSE 11 | ) 12 | } 13 | \arguments{ 14 | \item{cache_path}{The cache directory to clear. Defaults to the user-specific data directory.} 15 | 16 | \item{check}{Whether to list the contents of the cache directory before clearing it. Defaults to TRUE.} 17 | 18 | \item{delete_all}{Whether to delete all items without prompting. Defaults to FALSE.} 19 | } 20 | \value{ 21 | A message indicating whether the cache was cleared or not. 22 | } 23 | \description{ 24 | Clear the Java distributions cache folder 25 | } 26 | \keyword{internal} 27 | -------------------------------------------------------------------------------- /man/java_clear_in_project.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_manage_project.R 3 | \name{java_clear_in_project} 4 | \alias{java_clear_in_project} 5 | \title{Clear the Java versions symlinked in the current project} 6 | \usage{ 7 | java_clear_in_project(project_path = NULL, check = TRUE, delete_all = FALSE) 8 | } 9 | \arguments{ 10 | \item{project_path}{The project directory to clear. Defaults to the current working directory.} 11 | 12 | \item{check}{Whether to list the symlinked Java versions before clearing them. Defaults to TRUE.} 13 | 14 | \item{delete_all}{Whether to delete all symlinks without prompting. Defaults to FALSE.} 15 | } 16 | \value{ 17 | A message indicating whether the symlinks were cleared or not. 18 | } 19 | \description{ 20 | Clear the Java versions symlinked in the current project 21 | } 22 | \keyword{internal} 23 | -------------------------------------------------------------------------------- /man/java_clear_installed_cache.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_manage_installed_cache.R 3 | \name{java_clear_installed_cache} 4 | \alias{java_clear_installed_cache} 5 | \title{Clear the Java installations cache folder} 6 | \usage{ 7 | java_clear_installed_cache( 8 | check = TRUE, 9 | delete_all = FALSE, 10 | cache_path = getOption("rJavaEnv.cache_path") 11 | ) 12 | } 13 | \arguments{ 14 | \item{check}{Whether to list the contents of the cache directory before clearing it. Defaults to TRUE.} 15 | 16 | \item{delete_all}{Whether to delete all installations without prompting. Defaults to FALSE.} 17 | 18 | \item{cache_path}{The cache directory to clear. Defaults to the user-specific data directory.} 19 | } 20 | \value{ 21 | A message indicating whether the cache was cleared or not. 22 | } 23 | \description{ 24 | Clear the Java installations cache folder 25 | } 26 | \keyword{internal} 27 | -------------------------------------------------------------------------------- /man/java_download.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_download.R 3 | \name{java_download} 4 | \alias{java_download} 5 | \title{Download a Java distribution} 6 | \usage{ 7 | java_download( 8 | version = 21, 9 | distribution = "Corretto", 10 | cache_path = getOption("rJavaEnv.cache_path"), 11 | platform = platform_detect()$os, 12 | arch = platform_detect()$arch, 13 | quiet = FALSE, 14 | force = FALSE, 15 | temp_dir = FALSE 16 | ) 17 | } 18 | \arguments{ 19 | \item{version}{\code{Integer} or \code{character} vector of length 1 for major version of Java to download or install. If not specified, defaults to the latest LTS version. Can be "8", and "11" to "24" (or the same version numers in \code{integer}) or any newer version if it is available for the selected distribution. For \code{macOS} on \code{aarch64} architecture (Apple Silicion) certain \code{Java} versions are not available.} 20 | 21 | \item{distribution}{The Java distribution to download. If not specified, defaults to "Amazon Corretto". Currently only \href{https://aws.amazon.com/corretto/}{"Amazon Corretto"} is supported.} 22 | 23 | \item{cache_path}{The destination directory to download the Java distribution to. Defaults to a user-specific data directory.} 24 | 25 | \item{platform}{The platform for which to download the Java distribution. Defaults to the current platform.} 26 | 27 | \item{arch}{The architecture for which to download the Java distribution. Defaults to the current architecture.} 28 | 29 | \item{quiet}{A \code{logical} value indicating whether to suppress messages. Can be \code{TRUE} or \code{FALSE}.} 30 | 31 | \item{force}{A logical. Whether the distribution file should be overwritten or not. Defaults to \code{FALSE}.} 32 | 33 | \item{temp_dir}{A logical. Whether the file should be saved in a temporary directory. Defaults to \code{FALSE}.} 34 | } 35 | \value{ 36 | The path to the downloaded Java distribution file. 37 | } 38 | \description{ 39 | Download a Java distribution 40 | } 41 | \examples{ 42 | \dontrun{ 43 | 44 | # download distribution of Java version 17 45 | java_download(version = "17", temp_dir = TRUE) 46 | 47 | # download default Java distribution (version 21) 48 | java_download(temp_dir = TRUE) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /man/java_env_set.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_env.R 3 | \name{java_env_set} 4 | \alias{java_env_set} 5 | \title{Set the \code{JAVA_HOME} and \code{PATH} environment variables to a given path} 6 | \usage{ 7 | java_env_set( 8 | where = c("session", "both", "project"), 9 | java_home, 10 | project_path = NULL, 11 | quiet = FALSE 12 | ) 13 | } 14 | \arguments{ 15 | \item{where}{Where to set the \code{JAVA_HOME}: "session", "project", or "both". Defaults to "session" and only updates the paths in the current R session. When "both" or "project" is selected, the function updates the .Rprofile file in the project directory to set the JAVA_HOME and PATH environment variables at the start of the R session.} 16 | 17 | \item{java_home}{The path to the desired \code{JAVA_HOME}.} 18 | 19 | \item{project_path}{A \code{character} vector of length 1 containing the project directory where Java should be installed. If not specified or \code{NULL}, defaults to the current working directory.} 20 | 21 | \item{quiet}{A \code{logical} value indicating whether to suppress messages. Can be \code{TRUE} or \code{FALSE}.} 22 | } 23 | \value{ 24 | Nothing. Sets the JAVA_HOME and PATH environment variables. 25 | } 26 | \description{ 27 | Set the \code{JAVA_HOME} and \code{PATH} environment variables to a given path 28 | } 29 | \examples{ 30 | \dontrun{ 31 | # download, install Java 17 32 | java_17_distrib <- java_download(version = "17", temp_dir = TRUE) 33 | java_home <- java_install( 34 | java_distrib_path = java_17_distrib, 35 | project_path = tempdir(), 36 | autoset_java_env = FALSE 37 | ) 38 | 39 | # now manually set the JAVA_HOME and PATH environment variables in current session 40 | java_env_set( 41 | where = "session", 42 | java_home = java_home 43 | ) 44 | 45 | # or set JAVA_HOME and PATH in the spefific projects' .Rprofile 46 | java_env_set( 47 | where = "session", 48 | java_home = java_home, 49 | project_path = tempdir() 50 | ) 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /man/java_env_set_rprofile.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_env.R 3 | \name{java_env_set_rprofile} 4 | \alias{java_env_set_rprofile} 5 | \title{Update the .Rprofile file in the project directory} 6 | \usage{ 7 | java_env_set_rprofile(java_home, project_path = NULL) 8 | } 9 | \arguments{ 10 | \item{java_home}{The path to the desired JAVA_HOME.} 11 | 12 | \item{project_path}{A \code{character} vector of length 1 containing the project directory where Java should be installed. If not specified or \code{NULL}, defaults to the current working directory.} 13 | } 14 | \description{ 15 | Update the .Rprofile file in the project directory 16 | } 17 | \keyword{internal} 18 | -------------------------------------------------------------------------------- /man/java_env_set_session.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_env.R 3 | \name{java_env_set_session} 4 | \alias{java_env_set_session} 5 | \title{Set the JAVA_HOME and PATH environment variables for the current session} 6 | \usage{ 7 | java_env_set_session(java_home) 8 | } 9 | \arguments{ 10 | \item{java_home}{The path to the desired JAVA_HOME.} 11 | } 12 | \description{ 13 | Set the JAVA_HOME and PATH environment variables for the current session 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/java_env_unset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_env.R 3 | \name{java_env_unset} 4 | \alias{java_env_unset} 5 | \title{Unset the JAVA_HOME and PATH environment variables in the project .Rprofile} 6 | \usage{ 7 | java_env_unset(project_path = NULL, quiet = FALSE) 8 | } 9 | \arguments{ 10 | \item{project_path}{A \code{character} vector of length 1 containing the project directory where Java should be installed. If not specified or \code{NULL}, defaults to the current working directory.} 11 | 12 | \item{quiet}{A \code{logical} value indicating whether to suppress messages. Can be \code{TRUE} or \code{FALSE}.} 13 | } 14 | \value{ 15 | Nothing. Removes the JAVA_HOME and PATH environment variables settings from the project .Rprofile. 16 | } 17 | \description{ 18 | Unset the JAVA_HOME and PATH environment variables in the project .Rprofile 19 | } 20 | \examples{ 21 | \dontrun{ 22 | # clear the JAVA_HOME and PATH environment variables in the specified project .Rprofile 23 | java_env_unset(project_path = tempdir()) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /man/java_install.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_install.R 3 | \name{java_install} 4 | \alias{java_install} 5 | \title{Install Java from a distribution file} 6 | \usage{ 7 | java_install( 8 | java_distrib_path, 9 | project_path = NULL, 10 | autoset_java_env = TRUE, 11 | quiet = FALSE 12 | ) 13 | } 14 | \arguments{ 15 | \item{java_distrib_path}{A \code{character} vector of length 1 containing the path to the Java distribution file.} 16 | 17 | \item{project_path}{A \code{character} vector of length 1 containing the project directory where Java should be installed. If not specified or \code{NULL}, defaults to the current working directory.} 18 | 19 | \item{autoset_java_env}{A \code{logical} indicating whether to set the \code{JAVA_HOME} and \code{PATH} environment variables to the installed Java directory. Defaults to \code{TRUE}.} 20 | 21 | \item{quiet}{A \code{logical} value indicating whether to suppress messages. Can be \code{TRUE} or \code{FALSE}.} 22 | } 23 | \value{ 24 | The path to the installed Java directory. 25 | } 26 | \description{ 27 | Unpack Java distribution file into cache directory and link the installation into a project directory, optionally setting the \code{JAVA_HOME} and \code{PATH} environment variables to the Java version that was just installed. 28 | } 29 | \examples{ 30 | \dontrun{ 31 | 32 | # set cache dir to temporary directory 33 | options(rJavaEnv.cache_path = tempdir()) 34 | # download, install and autoset environmnet variables for Java 17 35 | java_17_distrib <- java_download(version = "17") 36 | java_install(java_distrib_path = java_17_distrib, project_path = tempdir()) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /man/java_list.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_manage.R 3 | \name{java_list} 4 | \alias{java_list} 5 | \title{List the contents of the Java versions installed or cached} 6 | \usage{ 7 | java_list( 8 | type = c("project", "installed", "distrib"), 9 | output = c("data.frame", "vector"), 10 | quiet = TRUE, 11 | target_dir = NULL 12 | ) 13 | } 14 | \arguments{ 15 | \item{type}{The type of cache to list: "distrib", "installed", or "project". Defaults to "project".} 16 | 17 | \item{output}{The format of the output: \verb{data.frame`` or }vector``. Defaults to \code{data.frame}.} 18 | 19 | \item{quiet}{A \code{logical} value indicating whether to suppress messages. Can be \code{TRUE} or \code{FALSE}.} 20 | 21 | \item{target_dir}{The cache directory to list. Defaults to the user-specific data directory for "distrib" and "installed", and the current working directory for "project".} 22 | } 23 | \value{ 24 | A \code{dataframe} or \code{character} \code{vector} with the contents of the specified cache or project directory. 25 | } 26 | \description{ 27 | This function lists one of the following: 28 | \itemize{ 29 | \item \code{project} - list the contents of the Java symlinked/copied in the current project or directory specified by \code{target_dir} 30 | \item \code{distrib} - list the contents of the downloaded Java distributions cache in default location or specified by \code{target_dir} 31 | \item \code{installed} - list the contents of the Java installations cache (unpacked distributions) in default location or specified by \code{target_dir} 32 | } 33 | } 34 | \examples{ 35 | \dontrun{ 36 | java_list("project") 37 | java_list("installed") 38 | java_list("distrib") 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /man/java_list_distrib_cache.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_manage_distrib_cache.R 3 | \name{java_list_distrib_cache} 4 | \alias{java_list_distrib_cache} 5 | \title{List the contents of the Java distributions cache folder} 6 | \usage{ 7 | java_list_distrib_cache( 8 | cache_path = getOption("rJavaEnv.cache_path"), 9 | output = c("data.frame", "vector"), 10 | quiet = TRUE 11 | ) 12 | } 13 | \arguments{ 14 | \item{cache_path}{The destination directory to download the Java distribution to. Defaults to a user-specific data directory.} 15 | 16 | \item{output}{The format of the output: "data.frame" or "vector". Defaults to "data.frame".} 17 | 18 | \item{quiet}{A \code{logical} value indicating whether to suppress messages. Can be \code{TRUE} or \code{FALSE}.} 19 | } 20 | \value{ 21 | A character vector with the contents of the cache directory. 22 | } 23 | \description{ 24 | List the contents of the Java distributions cache folder 25 | } 26 | \keyword{internal} 27 | -------------------------------------------------------------------------------- /man/java_list_in_project.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_manage_project.R 3 | \name{java_list_in_project} 4 | \alias{java_list_in_project} 5 | \title{List the Java versions symlinked in the current project} 6 | \usage{ 7 | java_list_in_project( 8 | project_path = NULL, 9 | output = c("data.frame", "vector"), 10 | quiet = TRUE 11 | ) 12 | } 13 | \arguments{ 14 | \item{project_path}{The project directory to list. Defaults to the current working directory.} 15 | 16 | \item{output}{The format of the output: "data.frame" or "vector". Defaults to "data.frame".} 17 | 18 | \item{quiet}{A \code{logical} value indicating whether to suppress messages. Can be \code{TRUE} or \code{FALSE}.} 19 | } 20 | \value{ 21 | A data frame or character vector with the symlinked Java versions in the project directory. 22 | } 23 | \description{ 24 | List the Java versions symlinked in the current project 25 | } 26 | \keyword{internal} 27 | -------------------------------------------------------------------------------- /man/java_list_installed_cache.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_manage_installed_cache.R 3 | \name{java_list_installed_cache} 4 | \alias{java_list_installed_cache} 5 | \title{List the contents of the Java installations cache folder} 6 | \usage{ 7 | java_list_installed_cache( 8 | output = c("data.frame", "vector"), 9 | quiet = TRUE, 10 | cache_path = getOption("rJavaEnv.cache_path") 11 | ) 12 | } 13 | \arguments{ 14 | \item{output}{The format of the output: "data.frame" or "vector". Defaults to "data.frame".} 15 | 16 | \item{quiet}{A \code{logical} value indicating whether to suppress messages. Can be \code{TRUE} or \code{FALSE}.} 17 | 18 | \item{cache_path}{The cache directory to list. Defaults to the user-specific data directory. Not recommended to change.} 19 | } 20 | \value{ 21 | A data frame or character vector with the contents of the cache directory. 22 | } 23 | \description{ 24 | List the contents of the Java installations cache folder 25 | } 26 | \keyword{internal} 27 | -------------------------------------------------------------------------------- /man/java_quick_install.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_quick_install.R 3 | \name{java_quick_install} 4 | \alias{java_quick_install} 5 | \title{Download and install and set Java in current working/project directory} 6 | \usage{ 7 | java_quick_install( 8 | version = 21, 9 | distribution = "Corretto", 10 | project_path = NULL, 11 | platform = platform_detect()$os, 12 | arch = platform_detect()$arch, 13 | quiet = FALSE, 14 | temp_dir = FALSE 15 | ) 16 | } 17 | \arguments{ 18 | \item{version}{\code{Integer} or \code{character} vector of length 1 for major version of Java to download or install. If not specified, defaults to the latest LTS version. Can be "8", and "11" to "24" (or the same version numers in \code{integer}) or any newer version if it is available for the selected distribution. For \code{macOS} on \code{aarch64} architecture (Apple Silicion) certain \code{Java} versions are not available.} 19 | 20 | \item{distribution}{The Java distribution to download. If not specified, defaults to "Amazon Corretto". Currently only \href{https://aws.amazon.com/corretto/}{"Amazon Corretto"} is supported.} 21 | 22 | \item{project_path}{A \code{character} vector of length 1 containing the project directory where Java should be installed. If not specified or \code{NULL}, defaults to the current working directory.} 23 | 24 | \item{platform}{The platform for which to download the Java distribution. Defaults to the current platform.} 25 | 26 | \item{arch}{The architecture for which to download the Java distribution. Defaults to the current architecture.} 27 | 28 | \item{quiet}{A \code{logical} value indicating whether to suppress messages. Can be \code{TRUE} or \code{FALSE}.} 29 | 30 | \item{temp_dir}{A logical. Whether the file should be saved in a temporary directory. Defaults to \code{FALSE}.} 31 | } 32 | \value{ 33 | Message indicating that Java was installed and set in the current working/project directory. 34 | } 35 | \description{ 36 | Download and install and set Java in current working/project directory 37 | } 38 | \examples{ 39 | \dontrun{ 40 | 41 | # quick download, unpack, install and set in current working directory default Java version (21) 42 | java_quick_install(17, temp_dir = TRUE) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /man/java_unpack.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_unpack.R 3 | \name{java_unpack} 4 | \alias{java_unpack} 5 | \title{Unpack a Java distribution file into cache directory} 6 | \usage{ 7 | java_unpack(java_distrib_path, quiet = FALSE) 8 | } 9 | \arguments{ 10 | \item{java_distrib_path}{A \code{character} vector of length 1 containing the path to the Java distribution file.} 11 | 12 | \item{quiet}{A \code{logical} value indicating whether to suppress messages. Can be \code{TRUE} or \code{FALSE}.} 13 | } 14 | \value{ 15 | A \code{character} vector containing of length 1 containing the path to the unpacked Java directory. 16 | } 17 | \description{ 18 | Unpack the Java distribution file into cache directory and return the path to the unpacked Java directory with Java binaries. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | 23 | # set cache dir to temporary directory 24 | options(rJavaEnv.cache_path = tempdir()) 25 | 26 | # download Java 17 distrib and unpack it into cache dir 27 | java_17_distrib <- java_download(version = "17") 28 | java_home <- java_unpack(java_distrib_path = java_17_distrib) 29 | 30 | # set the JAVA_HOME environment variable in the current session 31 | # to the cache dir without touching any files in the current project directory 32 | java_env_set(where = "session", java_home = java_home) 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /man/java_urls_load.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/internal_utilities.R 3 | \name{java_urls_load} 4 | \alias{java_urls_load} 5 | \title{Load Java URLs from JSON file} 6 | \usage{ 7 | java_urls_load() 8 | } 9 | \value{ 10 | A list with the Java URLs structured as in the JSON file by distribution, platform, and architecture. 11 | } 12 | \description{ 13 | Load Java URLs from JSON file 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/java_valid_major_versions_corretto.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_valid_versions.R 3 | \name{java_valid_major_versions_corretto} 4 | \alias{java_valid_major_versions_corretto} 5 | \title{Get Available Online Versions of Amazon Corretto} 6 | \usage{ 7 | java_valid_major_versions_corretto( 8 | arch = NULL, 9 | platform = NULL, 10 | imageType = "jdk" 11 | ) 12 | } 13 | \arguments{ 14 | \item{arch}{Optional character string for the target architecture (e.g., "x64"). 15 | If \code{NULL}, it is inferred using \code{platform_detect()}.} 16 | 17 | \item{platform}{Optional character string for the operating system (e.g., "windows", "macos", "linux"). 18 | If \code{NULL}, it is inferred using \code{platform_detect()}.} 19 | 20 | \item{imageType}{Optional character string to filter on; defaults to \code{"jdk"}. Can be set to \code{"jre"} for Windows Java Runtime Environment.} 21 | } 22 | \value{ 23 | A \code{character} vector of available major Corretto versions. 24 | } 25 | \description{ 26 | This function downloads the latest Amazon Corretto version information from the 27 | Corretto GitHub endpoint and returns a data frame with details for all eligible releases. 28 | } 29 | \details{ 30 | It leverages the existing \code{platform_detect()} function to infer the current operating 31 | system and architecture if these are not provided. 32 | } 33 | \keyword{internal} 34 | -------------------------------------------------------------------------------- /man/java_valid_versions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/java_valid_versions.R 3 | \name{java_valid_versions} 4 | \alias{java_valid_versions} 5 | \title{Retrieve Valid Java Versions} 6 | \usage{ 7 | java_valid_versions( 8 | distribution = "Corretto", 9 | platform = platform_detect()$os, 10 | arch = platform_detect()$arch, 11 | force = FALSE 12 | ) 13 | } 14 | \arguments{ 15 | \item{distribution}{The Java distribution to download. If not specified, defaults to "Amazon Corretto". Currently only \href{https://aws.amazon.com/corretto/}{"Amazon Corretto"} is supported.} 16 | 17 | \item{platform}{The platform for which to download the Java distribution. Defaults to the current platform.} 18 | 19 | \item{arch}{The architecture for which to download the Java distribution. Defaults to the current architecture.} 20 | 21 | \item{force}{Logical. If TRUE, forces a fresh API call even if a cached value exists. Defaults to FALSE.} 22 | } 23 | \value{ 24 | A character vector of valid Java versions. 25 | } 26 | \description{ 27 | This function retrieves a list of valid Java versions by querying an appropriate API endpoint based on the chosen distribution. 28 | The result is cached for 8 hours to avoid repeated API calls. If the API call fails (for example, due to a lack of internet connectivity), 29 | the function falls back to a pre-defined list of Java versions. 30 | } 31 | \examples{ 32 | \dontrun{ 33 | # Retrieve valid Java versions (cached if available) using Amazon Corretto endpoint 34 | versions <- java_valid_versions() 35 | 36 | # Force refresh the list of Java versions using the Oracle endpoint 37 | versions <- java_valid_versions(distribution = "Corretto", force = TRUE) 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /man/java_version_check_rscript.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/internal_utilities.R 3 | \name{java_version_check_rscript} 4 | \alias{java_version_check_rscript} 5 | \title{Check Java version using rJava} 6 | \usage{ 7 | java_version_check_rscript(java_home) 8 | } 9 | \arguments{ 10 | \item{java_home}{} 11 | } 12 | \value{ 13 | A message with the Java version or an error message. 14 | } 15 | \description{ 16 | Check Java version using rJava 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /man/platform_detect.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/internal_utilities.R 3 | \name{platform_detect} 4 | \alias{platform_detect} 5 | \title{Detect platform and architecture} 6 | \usage{ 7 | platform_detect(quiet = TRUE) 8 | } 9 | \arguments{ 10 | \item{quiet}{A \code{logical} value indicating whether to suppress messages. Can be \code{TRUE} or \code{FALSE}.} 11 | } 12 | \value{ 13 | A list of length 2 with the detected platform and architecture. 14 | } 15 | \description{ 16 | Detect platform and architecture 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /man/rJavaEnv-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rJavaEnv-package.R 3 | \docType{package} 4 | \name{rJavaEnv-package} 5 | \alias{rJavaEnv} 6 | \alias{rJavaEnv-package} 7 | \title{rJavaEnv: 'Java' Environments for R Projects} 8 | \description{ 9 | \if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}} 10 | 11 | Quickly install 'Java Development Kit (JDK)' without administrative privileges and set environment variables in current R session or project to solve common issues with 'Java' environment management in 'R'. Recommended to users of 'Java'/'rJava'-dependent 'R' packages such as 'r5r', 'opentripplanner', 'xlsx', 'openNLP', 'rWeka', 'RJDBC', 'tabulapdf', and many more. 'rJavaEnv' prevents common problems like 'Java' not found, 'Java' version conflicts, missing 'Java' installations, and the inability to install 'Java' due to lack of administrative privileges. 'rJavaEnv' automates the download, installation, and setup of the 'Java' on a per-project basis by setting the relevant 'JAVA_HOME' in the current 'R' session or the current working directory (via '.Rprofile', with the user's consent). Similar to what 'renv' does for 'R' packages, 'rJavaEnv' allows different 'Java' versions to be used across different projects, but can also be configured to allow multiple versions within the same project (e.g. with the help of 'targets' package). Note: there are a few extra steps for 'Linux' users, who don't have any 'Java' previously installed in their system, and who prefer package installation from source, rather then installing binaries from 'Posit Package Manager'. See documentation for details. 12 | } 13 | \seealso{ 14 | Useful links: 15 | \itemize{ 16 | \item \url{https://github.com/e-kotov/rJavaEnv} 17 | \item \url{https://www.ekotov.pro/rJavaEnv/} 18 | \item Report bugs at \url{https://github.com/e-kotov/rJavaEnv/issues} 19 | } 20 | 21 | } 22 | \author{ 23 | \strong{Maintainer}: Egor Kotov \email{kotov.egor@gmail.com} (\href{https://orcid.org/0000-0001-6690-5345}{ORCID}) [copyright holder] 24 | 25 | Authors: 26 | \itemize{ 27 | \item Chung-hong Chan \email{chainsawtiney@gmail.com} (\href{https://orcid.org/0000-0002-6232-7530}{ORCID}) 28 | } 29 | 30 | Other contributors: 31 | \itemize{ 32 | \item Mauricio Vargas \email{mavargas11@uc.cl} (\href{https://orcid.org/0000-0003-1017-7574}{ORCID}) [contributor] 33 | \item Hadley Wickham \email{hadley@posit.co} (use_java feature suggestion and PR review) [contributor] 34 | \item Enrique Mondragon-Estrada \email{enriquemondragon@proton.me} (\href{https://orcid.org/0009-0004-5592-1728}{ORCID}) [contributor] 35 | \item Jonas Lieth \email{jonas.lieth@gesis.org} (\href{https://orcid.org/0000-0002-3451-3176}{ORCID}) [contributor] 36 | } 37 | 38 | } 39 | \keyword{internal} 40 | -------------------------------------------------------------------------------- /man/rje_consent.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/consent.R 3 | \name{rje_consent} 4 | \alias{rje_consent} 5 | \title{Obtain User Consent for rJavaEnv} 6 | \usage{ 7 | rje_consent(provided = FALSE) 8 | } 9 | \arguments{ 10 | \item{provided}{Logical indicating if consent is already provided. 11 | To provide consent in non-interactive \R sessions 12 | use \code{rJavaEnv::rje_consent(provided = TRUE)}. Default is \code{FALSE}.} 13 | } 14 | \value{ 15 | \code{TRUE} if consent is given, otherwise an error is raised. 16 | } 17 | \description{ 18 | Get user consent for rJavaEnv to write and update files on the file system. 19 | rJavaEnv needs permission to manage files in your project and cache directories 20 | to function correctly. 21 | } 22 | \details{ 23 | In line with \href{https://cran.r-project.org/web/packages/policies.html}{CRAN policies}, explicit user consent is required before making these changes. 24 | Please call \code{rJavaEnv::consent()} to provide consent. 25 | 26 | Alternatively, you can set the following \R option 27 | (especially useful for non-interactive R sessions): 28 | 29 | \if{html}{\out{
}}\preformatted{options(rJavaEnv.consent = TRUE) 30 | }\if{html}{\out{
}} 31 | 32 | The function is based on the code of the \code{renv} package. 33 | Copyright 2023 Posit Software, PBC 34 | License: https://github.com/rstudio/renv/blob/main/LICENSE 35 | } 36 | \examples{ 37 | \dontrun{ 38 | 39 | # to provide consent and prevent other functions from interrupting to get the consent 40 | rje_consent(provided = TRUE) 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /man/rje_consent_check.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/consent.R 3 | \name{rje_consent_check} 4 | \alias{rje_consent_check} 5 | \title{Verify User Consent for rJavaEnv} 6 | \usage{ 7 | rje_consent_check() 8 | } 9 | \value{ 10 | \code{TRUE} if consent is verified, otherwise an error is raised. 11 | } 12 | \description{ 13 | Ensure that the user has granted permission for rJavaEnv to manage files on their file system. 14 | } 15 | \details{ 16 | The function is based on the code of the \code{renv} package. 17 | Copyright 2023 Posit Software, PBC 18 | License: https://github.com/rstudio/renv/blob/main/LICENSE 19 | } 20 | \keyword{internal} 21 | -------------------------------------------------------------------------------- /man/rje_envvar_exists.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/consent.R 3 | \name{rje_envvar_exists} 4 | \alias{rje_envvar_exists} 5 | \title{Helper for clean env var check} 6 | \usage{ 7 | rje_envvar_exists(key) 8 | } 9 | \arguments{ 10 | \item{key}{The environment variable key to check.} 11 | } 12 | \description{ 13 | #' The function is based on the code of the \code{renv} package. 14 | Copyright 2023 Posit Software, PBC 15 | License: https://github.com/rstudio/renv/blob/main/LICENSE 16 | } 17 | \keyword{internal} 18 | -------------------------------------------------------------------------------- /man/urls_test_all.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/internal_utilities.R 3 | \name{urls_test_all} 4 | \alias{urls_test_all} 5 | \title{Test all Java URLs} 6 | \usage{ 7 | urls_test_all() 8 | } 9 | \value{ 10 | A list with the results of testing all Java URLs. 11 | } 12 | \description{ 13 | Test all Java URLs 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/use_java.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/use_java.R 3 | \name{use_java} 4 | \alias{use_java} 5 | \title{Install specified Java version and set the \code{JAVA_HOME} and \code{PATH} environment variables in current R session} 6 | \usage{ 7 | use_java( 8 | version = NULL, 9 | distribution = "Corretto", 10 | cache_path = getOption("rJavaEnv.cache_path"), 11 | platform = platform_detect()$os, 12 | arch = platform_detect()$arch, 13 | quiet = TRUE 14 | ) 15 | } 16 | \arguments{ 17 | \item{version}{\code{Integer} or \code{character} vector of length 1 for major version of Java to download or install. If not specified, defaults to the latest LTS version. Can be "8", and "11" to "24" (or the same version numers in \code{integer}) or any newer version if it is available for the selected distribution. For \code{macOS} on \code{aarch64} architecture (Apple Silicion) certain \code{Java} versions are not available.} 18 | 19 | \item{distribution}{The Java distribution to download. If not specified, defaults to "Amazon Corretto". Currently only \href{https://aws.amazon.com/corretto/}{"Amazon Corretto"} is supported.} 20 | 21 | \item{cache_path}{The destination directory to download the Java distribution to. Defaults to a user-specific data directory.} 22 | 23 | \item{platform}{The platform for which to download the Java distribution. Defaults to the current platform.} 24 | 25 | \item{arch}{The architecture for which to download the Java distribution. Defaults to the current architecture.} 26 | 27 | \item{quiet}{A \code{logical} value indicating whether to suppress messages. Can be \code{TRUE} or \code{FALSE}.} 28 | } 29 | \value{ 30 | \code{NULL}. Prints the message that Java was set in the current R session if \code{quiet} is set to \code{FALSE}. 31 | } 32 | \description{ 33 | Using specified Java version, set the \code{JAVA_HOME} and \code{PATH} environment variables in the current R session. If Java distribtuion has not been downloaded yet, download it. If it was not installed into cache directory yet, install it there and then set the environment variables. This is intended as a quick and easy way to use different Java versions in R scripts that are in the same project, but require different Java versions. For example, one could use this in scripts that are called by \code{targets} package or \code{callr} package. 34 | } 35 | \examples{ 36 | \dontrun{ 37 | 38 | # set cache directory for Java to be in temporary directory 39 | options(rJavaEnv.cache_path = tempdir()) 40 | 41 | # install and set Java 8 in current R session 42 | use_java(8) 43 | # check Java version 44 | "8" == java_check_version_cmd(quiet = TRUE) 45 | "8" == java_check_version_rjava(quiet = TRUE) 46 | 47 | # install and set Java 17 in current R session 48 | use_java(17) 49 | # check Java version 50 | "17" == java_check_version_cmd(quiet = TRUE) 51 | "17" == java_check_version_rjava(quiet = TRUE) 52 | 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /pkgdown/assets/images/card.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-kotov/rJavaEnv/c92d57937daee003b04d132441e0824250a29e4a/pkgdown/assets/images/card.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-kotov/rJavaEnv/c92d57937daee003b04d132441e0824250a29e4a/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-kotov/rJavaEnv/c92d57937daee003b04d132441e0824250a29e4a/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-kotov/rJavaEnv/c92d57937daee003b04d132441e0824250a29e4a/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-kotov/rJavaEnv/c92d57937daee003b04d132441e0824250a29e4a/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-kotov/rJavaEnv/c92d57937daee003b04d132441e0824250a29e4a/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-kotov/rJavaEnv/c92d57937daee003b04d132441e0824250a29e4a/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-kotov/rJavaEnv/c92d57937daee003b04d132441e0824250a29e4a/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-kotov/rJavaEnv/c92d57937daee003b04d132441e0824250a29e4a/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-96x96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-kotov/rJavaEnv/c92d57937daee003b04d132441e0824250a29e4a/pkgdown/favicon/favicon-96x96.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-kotov/rJavaEnv/c92d57937daee003b04d132441e0824250a29e4a/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /pkgdown/favicon/site.webmanifest: -------------------------------------------------------------------------------- 1 | { 2 | "name": "", 3 | "short_name": "", 4 | "icons": [ 5 | { 6 | "src": "/web-app-manifest-192x192.png", 7 | "sizes": "192x192", 8 | "type": "image/png", 9 | "purpose": "maskable" 10 | }, 11 | { 12 | "src": "/web-app-manifest-512x512.png", 13 | "sizes": "512x512", 14 | "type": "image/png", 15 | "purpose": "maskable" 16 | } 17 | ], 18 | "theme_color": "#ffffff", 19 | "background_color": "#ffffff", 20 | "display": "standalone" 21 | } -------------------------------------------------------------------------------- /pkgdown/favicon/web-app-manifest-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-kotov/rJavaEnv/c92d57937daee003b04d132441e0824250a29e4a/pkgdown/favicon/web-app-manifest-192x192.png -------------------------------------------------------------------------------- /pkgdown/favicon/web-app-manifest-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/e-kotov/rJavaEnv/c92d57937daee003b04d132441e0824250a29e4a/pkgdown/favicon/web-app-manifest-512x512.png -------------------------------------------------------------------------------- /rJavaEnv.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | LineEndingConversion: Posix 18 | 19 | BuildType: Package 20 | PackageUseDevtools: Yes 21 | PackageInstallArgs: --no-multiarch --with-keep.source 22 | PackageRoxygenize: rd,collate,namespace,vignette 23 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | # This file is part of the standard setup for testthat. 2 | # It is recommended that you do not modify it. 3 | # 4 | # Where should you do additional test configuration? 5 | # Learn more about the roles of various files in: 6 | # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview 7 | # * https://testthat.r-lib.org/articles/special-files.html 8 | 9 | library(testthat) 10 | library(rJavaEnv) 11 | 12 | test_check("rJavaEnv") 13 | -------------------------------------------------------------------------------- /tests/testthat/test-java_unpack.R: -------------------------------------------------------------------------------- 1 | test_that("bad java_distrib_path", { 2 | bad_path <- tempfile() 3 | expect_error(java_unpack(bad_path)) 4 | 5 | bad_path <- "/home/johndoe/.cache/R/rJavaEnv/distrib/amazon-corretto-21-x64-linux-jdk.tar.7z" 6 | expect_error(java_unpack(bad_path), "Unsupported file format") 7 | 8 | bad_path <- "/home/johndoe/.cache/R/rJavaEnv/distrib/amazon-corretto-x64-linux-jdk.tar.zip" 9 | expect_error(java_unpack(bad_path), "Java version") 10 | 11 | bad_path <- "/home/johndoe/.cache/R/rJavaEnv/distrib/amazon-corretto-21-linux-jdk.tar.zip" 12 | expect_error(java_unpack(bad_path), "architecture") 13 | 14 | bad_path <- "/home/johndoe/.cache/R/rJavaEnv/distrib/amazon-corretto-21-x64-msdos-jdk.tar.zip" 15 | expect_error(java_unpack(bad_path), "platform") 16 | 17 | }) 18 | -------------------------------------------------------------------------------- /tests/testthat/test-java_valid_versions.R: -------------------------------------------------------------------------------- 1 | test_that("java_valid_versions returns a character vector with required versions", { 2 | skip_on_cran() 3 | # Clear any cached values 4 | options( 5 | rJavaEnv.valid_versions_cache = NULL, 6 | rJavaEnv.valid_versions_timestamp = NULL 7 | ) 8 | 9 | # Retrieve Java versions 10 | versions <- java_valid_versions() 11 | 12 | # Verify the result is a character vector and contains "8" and "11" 13 | expect_type(versions, "character") 14 | expect_true("8" %in% versions) 15 | expect_true("11" %in% versions) 16 | expect_true("24" %in% versions) 17 | }) 18 | 19 | test_that("force parameter bypasses the cache", { 20 | # Set a fake cache in the options 21 | fake_cache <- c("8", "11") 22 | options( 23 | rJavaEnv.valid_versions_cache = fake_cache, 24 | rJavaEnv.valid_versions_timestamp = Sys.time() 25 | ) 26 | 27 | # Force a refresh by setting force = TRUE. 28 | versions_force <- java_valid_versions(force = TRUE) 29 | 30 | # The returned value should not equal the fake cache. 31 | expect_false(identical(versions_force, fake_cache)) 32 | }) 33 | 34 | test_that("fallback is used when the API call fails", { 35 | # Clear the cache to force an API call. 36 | options( 37 | rJavaEnv.valid_versions_cache = NULL, 38 | rJavaEnv.valid_versions_timestamp = NULL 39 | ) 40 | 41 | local_mocked_bindings( 42 | read_json = function(...) stop("Simulated API failure"), 43 | .package = "jsonlite" 44 | ) 45 | 46 | fallback <- getOption("rJavaEnv.fallback_valid_versions_current_platform") 47 | versions <- java_valid_versions(force = TRUE) 48 | 49 | ## When the API call fails, the fallback list should be returned. 50 | expect_equal(versions, fallback) 51 | }) 52 | -------------------------------------------------------------------------------- /tools/meta-data-update-and-submission.R: -------------------------------------------------------------------------------- 1 | # before release 2 | # usethis::use_version("patch") 3 | usethis::use_tidy_description() 4 | cffr::cff_write() 5 | codemetar::write_codemeta(write_minimeta = T) 6 | # urlchecker::url_check() 7 | # devtools::check(remote = TRUE, manual = TRUE) 8 | # devtools::check_win_devel() 9 | # revdepcheck::revdep_check(num_workers = 4) 10 | 11 | # devtools::submit_cran() 12 | 13 | # usethis::use_github_release() 14 | # usethis::use_dev_version(push = TRUE) 15 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | /.quarto/ 2 | -------------------------------------------------------------------------------- /vignettes/bibliography.bib: -------------------------------------------------------------------------------- 1 | @article{pereira_r5r_2021, 2 | title = {r5r: Rapid Realistic Routing on Multimodal Transport Networks with {R}$^{\textrm{5}}$ in R}, 3 | shorttitle = {r5r}, 4 | url = {https://findingspress.org/article/21262-r5r-rapid-realistic-routing-on-multimodal-transport-networks-with-r-5-in-r}, 5 | doi = {10.32866/001c.21262}, 6 | language = {en}, 7 | urldate = {2021-03-04}, 8 | journal = {Findings}, 9 | author = {Pereira, Rafael H. M. and Saraiva, Marcus and Herszenhut, Daniel and Braga, Carlos Kaue Vieira and Conway, Matthew Wigginton}, 10 | month = mar, 11 | year = {2021}, 12 | note = {Publisher: Network Design Lab} 13 | } 14 | 15 | , 16 | 17 | @Manual{rjdbc, 18 | title = {RJDBC: Provides Access to Databases Through the JDBC Interface}, 19 | author = {Simon Urbanek}, 20 | year = {2022}, 21 | note = {R package version 0.2-10}, 22 | url = {https://CRAN.R-project.org/package=RJDBC}, 23 | } 24 | , 25 | 26 | @Manual{mailr, 27 | title = {mailR: A Utility to Send Emails from R}, 28 | author = {Rahul Premraj}, 29 | year = {2021}, 30 | note = {R package version 0.8}, 31 | url = {https://CRAN.R-project.org/package=mailR}, 32 | } 33 | 34 | , 35 | 36 | 37 | @Article{rweka, 38 | title = {Open-Source Machine Learning: {R} Meets {Weka}}, 39 | author = {Kurt Hornik and Christian Buchta and Achim Zeileis}, 40 | journal = {Computational Statistics}, 41 | year = {2009}, 42 | volume = {24}, 43 | number = {2}, 44 | pages = {225--232}, 45 | doi = {10.1007/s00180-008-0119-7}, 46 | } 47 | 48 | , 49 | 50 | @Manual{opennlp, 51 | title = {openNLP: Apache OpenNLP Tools Interface}, 52 | author = {Kurt Hornik}, 53 | year = {2019}, 54 | note = {R package version 0.2-7}, 55 | url = {https://CRAN.R-project.org/package=openNLP}, 56 | } 57 | 58 | , 59 | 60 | @Manual{xlsx, 61 | title = {xlsx: Read, Write, Format Excel 2007 and Excel 97/2000/XP/2003 Files}, 62 | author = {Adrian Dragulescu and Cole Arendt}, 63 | year = {2020}, 64 | note = {R package version 0.6.5}, 65 | url = {https://CRAN.R-project.org/package=xlsx}, 66 | } 67 | 68 | @Manual{rjava, 69 | title = {rJava: Low-Level R to Java Interface}, 70 | author = {Simon Urbanek}, 71 | year = {2024}, 72 | note = {R package version 1.0-11}, 73 | url = {https://CRAN.R-project.org/package=rJava}, 74 | } 75 | -------------------------------------------------------------------------------- /vignettes/data-for-vignettes/data_table_dlstats.csv: -------------------------------------------------------------------------------- 1 | start;end;downloads;package 2 | 2014-01-01;2014-01-31;5308;data.table 3 | 2014-02-01;2014-02-28;6363;data.table 4 | 2014-03-01;2014-03-31;9784;data.table 5 | 2014-04-01;2014-04-30;12796;data.table 6 | 2014-05-01;2014-05-31;12312;data.table 7 | 2014-06-01;2014-06-30;13502;data.table 8 | 2014-07-01;2014-07-31;14397;data.table 9 | 2014-08-01;2014-08-31;14224;data.table 10 | 2014-09-01;2014-09-30;14193;data.table 11 | 2014-10-01;2014-10-31;21691;data.table 12 | 2014-11-01;2014-11-30;19681;data.table 13 | 2014-12-01;2014-12-31;17256;data.table 14 | 2015-01-01;2015-01-31;19970;data.table 15 | 2015-02-01;2015-02-28;21808;data.table 16 | 2015-03-01;2015-03-31;26032;data.table 17 | 2015-04-01;2015-04-30;31241;data.table 18 | 2015-05-01;2015-05-31;32581;data.table 19 | 2015-06-01;2015-06-30;35062;data.table 20 | 2015-07-01;2015-07-31;36540;data.table 21 | 2015-08-01;2015-08-31;50404;data.table 22 | 2015-09-01;2015-09-30;61375;data.table 23 | 2015-10-01;2015-10-31;64900;data.table 24 | 2015-11-01;2015-11-30;67938;data.table 25 | 2015-12-01;2015-12-31;61084;data.table 26 | 2016-01-01;2016-01-31;66463;data.table 27 | 2016-02-01;2016-02-29;65813;data.table 28 | 2016-03-01;2016-03-31;63233;data.table 29 | 2016-04-01;2016-04-30;59395;data.table 30 | 2016-05-01;2016-05-31;117233;data.table 31 | 2016-06-01;2016-06-30;110241;data.table 32 | 2016-07-01;2016-07-31;104528;data.table 33 | 2016-08-01;2016-08-31;108044;data.table 34 | 2016-09-01;2016-09-30;127614;data.table 35 | 2016-10-01;2016-10-31;146051;data.table 36 | 2016-11-01;2016-11-30;183043;data.table 37 | 2016-12-01;2016-12-31;181973;data.table 38 | 2017-01-01;2017-01-31;168188;data.table 39 | 2017-02-01;2017-02-28;265672;data.table 40 | 2017-03-01;2017-03-31;236241;data.table 41 | 2017-04-01;2017-04-30;199142;data.table 42 | 2017-05-01;2017-05-31;192961;data.table 43 | 2017-06-01;2017-06-30;185656;data.table 44 | 2017-07-01;2017-07-31;161976;data.table 45 | 2017-08-01;2017-08-31;156174;data.table 46 | 2017-09-01;2017-09-30;188326;data.table 47 | 2017-10-01;2017-10-31;325890;data.table 48 | 2017-11-01;2017-11-30;289248;data.table 49 | 2017-12-01;2017-12-31;212365;data.table 50 | 2018-01-01;2018-01-31;214533;data.table 51 | 2018-02-01;2018-02-28;219905;data.table 52 | 2018-03-01;2018-03-31;244143;data.table 53 | 2018-04-01;2018-04-30;297276;data.table 54 | 2018-05-01;2018-05-31;412734;data.table 55 | 2018-06-01;2018-06-30;304389;data.table 56 | 2018-07-01;2018-07-31;297191;data.table 57 | 2018-08-01;2018-08-31;273482;data.table 58 | 2018-09-01;2018-09-30;403235;data.table 59 | 2018-10-01;2018-10-31;491636;data.table 60 | 2018-11-01;2018-11-30;424741;data.table 61 | 2018-12-01;2018-12-31;330548;data.table 62 | 2019-01-01;2019-01-31;668709;data.table 63 | 2019-02-01;2019-02-28;666770;data.table 64 | 2019-03-01;2019-03-31;668349;data.table 65 | 2019-04-01;2019-04-30;729934;data.table 66 | 2019-05-01;2019-05-31;618185;data.table 67 | 2019-06-01;2019-06-30;444470;data.table 68 | 2019-07-01;2019-07-31;495586;data.table 69 | 2019-08-01;2019-08-31;454263;data.table 70 | 2019-09-01;2019-09-30;515846;data.table 71 | 2019-10-01;2019-10-31;715833;data.table 72 | 2019-11-01;2019-11-30;566063;data.table 73 | 2019-12-01;2019-12-31;500906;data.table 74 | 2020-01-01;2020-01-31;525533;data.table 75 | 2020-02-01;2020-02-29;502941;data.table 76 | 2020-03-01;2020-03-31;571181;data.table 77 | 2020-04-01;2020-04-30;596472;data.table 78 | 2020-05-01;2020-05-31;594441;data.table 79 | 2020-06-01;2020-06-30;562159;data.table 80 | 2020-07-01;2020-07-31;548913;data.table 81 | 2020-08-01;2020-08-31;584097;data.table 82 | 2020-09-01;2020-09-30;660371;data.table 83 | 2020-10-01;2020-10-31;745488;data.table 84 | 2020-11-01;2020-11-30;711626;data.table 85 | 2020-12-01;2020-12-31;667454;data.table 86 | 2021-01-01;2021-01-31;684310;data.table 87 | 2021-02-01;2021-02-28;696210;data.table 88 | 2021-03-01;2021-03-31;814729;data.table 89 | 2021-04-01;2021-04-30;743535;data.table 90 | 2021-05-01;2021-05-31;719963;data.table 91 | 2021-06-01;2021-06-30;730959;data.table 92 | 2021-07-01;2021-07-31;636526;data.table 93 | 2021-08-01;2021-08-31;661484;data.table 94 | 2021-09-01;2021-09-30;835160;data.table 95 | 2021-10-01;2021-10-31;943031;data.table 96 | 2021-11-01;2021-11-30;850174;data.table 97 | 2021-12-01;2021-12-31;763067;data.table 98 | 2022-01-01;2022-01-31;799994;data.table 99 | 2022-02-01;2022-02-28;800786;data.table 100 | 2022-03-01;2022-03-31;911517;data.table 101 | 2022-04-01;2022-04-30;909134;data.table 102 | 2022-05-01;2022-05-31;958481;data.table 103 | 2022-06-01;2022-06-30;891046;data.table 104 | 2022-07-01;2022-07-31;816538;data.table 105 | 2022-08-01;2022-08-31;848647;data.table 106 | 2022-09-01;2022-09-30;855167;data.table 107 | 2022-10-01;2022-10-31;962825;data.table 108 | 2022-11-01;2022-11-30;1117776;data.table 109 | 2022-12-01;2022-12-31;821153;data.table 110 | 2023-01-01;2023-01-31;748596;data.table 111 | 2023-02-01;2023-02-28;789184;data.table 112 | 2023-03-01;2023-03-31;913025;data.table 113 | 2023-04-01;2023-04-30;775531;data.table 114 | 2023-05-01;2023-05-31;779533;data.table 115 | 2023-06-01;2023-06-30;676283;data.table 116 | 2023-07-01;2023-07-31;570552;data.table 117 | 2023-08-01;2023-08-31;586248;data.table 118 | 2023-09-01;2023-09-30;694988;data.table 119 | 2023-10-01;2023-10-31;696944;data.table 120 | 2023-11-01;2023-11-30;965821;data.table 121 | 2023-12-01;2023-12-31;638954;data.table 122 | 2024-01-01;2024-01-31;739831;data.table 123 | 2024-02-01;2024-02-29;821539;data.table 124 | 2024-03-01;2024-03-31;845520;data.table 125 | 2024-04-01;2024-04-30;886330;data.table 126 | 2024-05-01;2024-05-31;846726;data.table 127 | 2024-06-01;2024-06-30;677560;data.table 128 | 2024-07-01;2024-07-31;698441;data.table 129 | 2024-08-01;2024-08-31;749291;data.table 130 | 2024-09-01;2024-09-26;729796;data.table 131 | -------------------------------------------------------------------------------- /vignettes/data-for-vignettes/get-data-for-vignettes.R: -------------------------------------------------------------------------------- 1 | if (!requireNamespace("pacman", quietly = TRUE)) { 2 | install.packages("pacman") 3 | } 4 | package_list <- c("devtools", "dlstats", "tidyverse") 5 | pacman::p_load(char = package_list) 6 | rm(package_list) 7 | 8 | 9 | dlstats::set_cran_start_year(2014) 10 | 11 | rJava_dependants <- devtools::revdep("rJava", dependencies = c("Imports", "Depends"), bioconductor = TRUE) 12 | 13 | rJava_dlstats <- dlstats::cran_stats("rJava", use_cache = FALSE) 14 | rJava_dependants_dlstats_cran <- dlstats::cran_stats(rJava_dependants, use_cache = FALSE) 15 | rJava_dependants_dlstats_bioc <- dlstats::bioc_stats(rJava_dependants, use_cache = FALSE, type = "Software") 16 | data_table_dlstats <- dlstats::cran_stats("data.table", use_cache = FALSE) 17 | ggplot2_dlstats <- dlstats::cran_stats("ggplot2", use_cache = FALSE) 18 | 19 | 20 | 21 | write_csv2(rJava_dlstats, "vignettes/data-for-vignettes/rJava_dlstats.csv") 22 | write_csv2(rJava_dependants_dlstats_cran, "vignettes/data-for-vignettes/rJava_dependants_dlstats_cran.csv") 23 | write_csv2(rJava_dependants_dlstats_bioc, "vignettes/data-for-vignettes/rJava_dependants_dlstats_bioc.csv") 24 | write_csv2(data_table_dlstats, "vignettes/data-for-vignettes/data_table_dlstats.csv") 25 | write_csv2(ggplot2_dlstats, "vignettes/data-for-vignettes/ggplot2_dlstats.csv") 26 | -------------------------------------------------------------------------------- /vignettes/data-for-vignettes/ggplot2_dlstats.csv: -------------------------------------------------------------------------------- 1 | start;end;downloads;package 2 | 2014-01-01;2014-01-31;33457;ggplot2 3 | 2014-02-01;2014-02-28;36817;ggplot2 4 | 2014-03-01;2014-03-31;47652;ggplot2 5 | 2014-04-01;2014-04-30;55404;ggplot2 6 | 2014-05-01;2014-05-31;54371;ggplot2 7 | 2014-06-01;2014-06-30;201761;ggplot2 8 | 2014-07-01;2014-07-31;92133;ggplot2 9 | 2014-08-01;2014-08-31;56890;ggplot2 10 | 2014-09-01;2014-09-30;70136;ggplot2 11 | 2014-10-01;2014-10-31;82817;ggplot2 12 | 2014-11-01;2014-11-30;79063;ggplot2 13 | 2014-12-01;2014-12-31;65079;ggplot2 14 | 2015-01-01;2015-01-31;85349;ggplot2 15 | 2015-02-01;2015-02-28;95591;ggplot2 16 | 2015-03-01;2015-03-31;140066;ggplot2 17 | 2015-04-01;2015-04-30;146008;ggplot2 18 | 2015-05-01;2015-05-31;142558;ggplot2 19 | 2015-06-01;2015-06-30;134730;ggplot2 20 | 2015-07-01;2015-07-31;126061;ggplot2 21 | 2015-08-01;2015-08-31;136617;ggplot2 22 | 2015-09-01;2015-09-30;176111;ggplot2 23 | 2015-10-01;2015-10-31;195243;ggplot2 24 | 2015-11-01;2015-11-30;198381;ggplot2 25 | 2015-12-01;2015-12-31;181234;ggplot2 26 | 2016-01-01;2016-01-31;228779;ggplot2 27 | 2016-02-01;2016-02-29;247028;ggplot2 28 | 2016-03-01;2016-03-31;262481;ggplot2 29 | 2016-04-01;2016-04-30;219765;ggplot2 30 | 2016-05-01;2016-05-31;249214;ggplot2 31 | 2016-06-01;2016-06-30;236981;ggplot2 32 | 2016-07-01;2016-07-31;210707;ggplot2 33 | 2016-08-01;2016-08-31;226941;ggplot2 34 | 2016-09-01;2016-09-30;294401;ggplot2 35 | 2016-10-01;2016-10-31;326941;ggplot2 36 | 2016-11-01;2016-11-30;435630;ggplot2 37 | 2016-12-01;2016-12-31;335209;ggplot2 38 | 2017-01-01;2017-01-31;411301;ggplot2 39 | 2017-02-01;2017-02-28;407285;ggplot2 40 | 2017-03-01;2017-03-31;464633;ggplot2 41 | 2017-04-01;2017-04-30;433774;ggplot2 42 | 2017-05-01;2017-05-31;420708;ggplot2 43 | 2017-06-01;2017-06-30;359623;ggplot2 44 | 2017-07-01;2017-07-31;318111;ggplot2 45 | 2017-08-01;2017-08-31;311367;ggplot2 46 | 2017-09-01;2017-09-30;389654;ggplot2 47 | 2017-10-01;2017-10-31;450465;ggplot2 48 | 2017-11-01;2017-11-30;454752;ggplot2 49 | 2017-12-01;2017-12-31;351634;ggplot2 50 | 2018-01-01;2018-01-31;419372;ggplot2 51 | 2018-02-01;2018-02-28;415838;ggplot2 52 | 2018-03-01;2018-03-31;495357;ggplot2 53 | 2018-04-01;2018-04-30;511879;ggplot2 54 | 2018-05-01;2018-05-31;507604;ggplot2 55 | 2018-06-01;2018-06-30;439156;ggplot2 56 | 2018-07-01;2018-07-31;552553;ggplot2 57 | 2018-08-01;2018-08-31;497218;ggplot2 58 | 2018-09-01;2018-09-30;647281;ggplot2 59 | 2018-10-01;2018-10-31;822873;ggplot2 60 | 2018-11-01;2018-11-30;809889;ggplot2 61 | 2018-12-01;2018-12-31;585313;ggplot2 62 | 2019-01-01;2019-01-31;726400;ggplot2 63 | 2019-02-01;2019-02-28;720326;ggplot2 64 | 2019-03-01;2019-03-31;771832;ggplot2 65 | 2019-04-01;2019-04-30;830500;ggplot2 66 | 2019-05-01;2019-05-31;830059;ggplot2 67 | 2019-06-01;2019-06-30;702976;ggplot2 68 | 2019-07-01;2019-07-31;712857;ggplot2 69 | 2019-08-01;2019-08-31;719862;ggplot2 70 | 2019-09-01;2019-09-30;988740;ggplot2 71 | 2019-10-01;2019-10-31;1058606;ggplot2 72 | 2019-11-01;2019-11-30;958562;ggplot2 73 | 2019-12-01;2019-12-31;869022;ggplot2 74 | 2020-01-01;2020-01-31;990079;ggplot2 75 | 2020-02-01;2020-02-29;1021046;ggplot2 76 | 2020-03-01;2020-03-31;1743064;ggplot2 77 | 2020-04-01;2020-04-30;1788712;ggplot2 78 | 2020-05-01;2020-05-31;1688318;ggplot2 79 | 2020-06-01;2020-06-30;1653368;ggplot2 80 | 2020-07-01;2020-07-31;1455078;ggplot2 81 | 2020-08-01;2020-08-31;1400458;ggplot2 82 | 2020-09-01;2020-09-30;1585801;ggplot2 83 | 2020-10-01;2020-10-31;1696668;ggplot2 84 | 2020-11-01;2020-11-30;1801691;ggplot2 85 | 2020-12-01;2020-12-31;905064;ggplot2 86 | 2021-01-01;2021-01-31;1128155;ggplot2 87 | 2021-02-01;2021-02-28;946051;ggplot2 88 | 2021-03-01;2021-03-31;1851241;ggplot2 89 | 2021-04-01;2021-04-30;1900989;ggplot2 90 | 2021-05-01;2021-05-31;1983929;ggplot2 91 | 2021-06-01;2021-06-30;1957952;ggplot2 92 | 2021-07-01;2021-07-31;1948565;ggplot2 93 | 2021-08-01;2021-08-31;2072506;ggplot2 94 | 2021-09-01;2021-09-30;2971064;ggplot2 95 | 2021-10-01;2021-10-31;3298060;ggplot2 96 | 2021-11-01;2021-11-30;3162372;ggplot2 97 | 2021-12-01;2021-12-31;2376174;ggplot2 98 | 2022-01-01;2022-01-31;2091880;ggplot2 99 | 2022-02-01;2022-02-28;2077216;ggplot2 100 | 2022-03-01;2022-03-31;2422703;ggplot2 101 | 2022-04-01;2022-04-30;2689183;ggplot2 102 | 2022-05-01;2022-05-31;3113536;ggplot2 103 | 2022-06-01;2022-06-30;2849346;ggplot2 104 | 2022-07-01;2022-07-31;2676911;ggplot2 105 | 2022-08-01;2022-08-31;2594350;ggplot2 106 | 2022-09-01;2022-09-30;2754884;ggplot2 107 | 2022-10-01;2022-10-31;2905716;ggplot2 108 | 2022-11-01;2022-11-30;2930801;ggplot2 109 | 2022-12-01;2022-12-31;2351346;ggplot2 110 | 2023-01-01;2023-01-31;2356847;ggplot2 111 | 2023-02-01;2023-02-28;2307038;ggplot2 112 | 2023-03-01;2023-03-31;2484066;ggplot2 113 | 2023-04-01;2023-04-30;1966351;ggplot2 114 | 2023-05-01;2023-05-31;2502717;ggplot2 115 | 2023-06-01;2023-06-30;2507430;ggplot2 116 | 2023-07-01;2023-07-31;2430173;ggplot2 117 | 2023-08-01;2023-08-31;2534005;ggplot2 118 | 2023-09-01;2023-09-30;2655965;ggplot2 119 | 2023-10-01;2023-10-31;2917801;ggplot2 120 | 2023-11-01;2023-11-30;3000819;ggplot2 121 | 2023-12-01;2023-12-31;2225776;ggplot2 122 | 2024-01-01;2024-01-31;2248917;ggplot2 123 | 2024-02-01;2024-02-29;2289545;ggplot2 124 | 2024-03-01;2024-03-31;2469492;ggplot2 125 | 2024-04-01;2024-04-30;1932736;ggplot2 126 | 2024-05-01;2024-05-31;1891742;ggplot2 127 | 2024-06-01;2024-06-30;1599144;ggplot2 128 | 2024-07-01;2024-07-31;1536478;ggplot2 129 | 2024-08-01;2024-08-31;1458005;ggplot2 130 | 2024-09-01;2024-09-26;1329676;ggplot2 131 | -------------------------------------------------------------------------------- /vignettes/data-for-vignettes/produce-graphs-for-why-rJavaEnv.R: -------------------------------------------------------------------------------- 1 | if (!requireNamespace("pacman", quietly = TRUE)) { 2 | install.packages("pacman") 3 | } 4 | package_list <- c("tidyverse", "scales", "ggpubr", "directlabels", "lubridate", "gghighlight", "resmush") 5 | pacman::p_load(char = package_list) 6 | rm(package_list) 7 | 8 | rJava_dlstats <- readr::read_csv2("vignettes/data-for-vignettes/rJava_dlstats.csv") 9 | rJava_dependants_dlstats_cran <- readr::read_csv2("vignettes/data-for-vignettes/rJava_dependants_dlstats_cran.csv") 10 | rJava_dependants_dlstats_bioc <- readr::read_csv2("vignettes/data-for-vignettes/rJava_dependants_dlstats_bioc.csv") 11 | data_table_dlstats <- readr::read_csv2("vignettes/data-for-vignettes/data_table_dlstats.csv") 12 | ggplot2_dlstats <- readr::read_csv2("vignettes/data-for-vignettes/ggplot2_dlstats.csv") 13 | 14 | cutoff_date <- "2024-09-26" 15 | 16 | rj_and_rj_dep_total_down <- rJava_dependants_dlstats_cran |> 17 | rbind(rJava_dlstats) |> 18 | rbind(data_table_dlstats) |> 19 | rbind(ggplot2_dlstats) |> 20 | mutate(is_rJava = if_else(package == "rJava", "rJava", "rJava dependent")) |> 21 | mutate(is_rJava = if_else(package == "ggplot2", "ggplot2", is_rJava)) |> 22 | mutate(is_rJava = if_else(package == "data.table", "data.table", is_rJava)) |> 23 | group_by(start, end, is_rJava) |> 24 | summarise(downloads = sum(downloads, na.rm = T), .groups = "keep") |> 25 | ungroup() 26 | 27 | 28 | # Define the custom positioning method 29 | # thanks to https://stackoverflow.com/a/19943864/2956729 30 | # Define the custom positioning method 31 | do.not.reduce <- list( 32 | cex = 1.5, 33 | "last.points", 34 | "calc.boxes", 35 | dl.trans(x = x + 0.3), # Shift labels to the right 36 | qp.labels("y", "bottom", "top", make.tiebreaker("x", "y")) 37 | ) 38 | 39 | 40 | # Overall popularity of rJava vs ggplot and data.table -------------------- 41 | 42 | 43 | # Overall popularity # rJavaPopularity 44 | p_rJavaPopularity <- rj_and_rj_dep_total_down |> 45 | # filter(downloads < 1000000) |> 46 | ggplot(aes(x = start, y = downloads)) + 47 | geom_line(aes(col = is_rJava, linetype = is_rJava)) + 48 | # geom_line(aes(col = is_rJava)) + 49 | scale_x_date(date_breaks = "1 year", date_labels = "%Y") + 50 | scale_y_continuous(labels = scales::label_number(), breaks = seq(0,3000000,500000)) + 51 | scale_color_manual(values = c("rJava" = "darkblue", "rJava dependent" = "darkgreen", "ggplot2" = "grey40", "data.table" = "grey40")) + 52 | scale_linetype_manual(values = c("rJava" = "solid", "rJava dependent" = "solid", "ggplot2" = "dashed", "data.table" = "dashed" )) + 53 | geom_dl(aes(label = is_rJava, color = is_rJava), 54 | method = do.not.reduce) + 55 | labs(title = "CRAN Downloads Over Time for rJava and rJava-dependent Packages", 56 | subtitle = "compared to popular ggplot2 and data.table for context", 57 | x = "Date", 58 | y = "Downloads", 59 | color = "Package") + 60 | theme_pubclean(base_size = 18) + 61 | theme(plot.margin = unit(c(1, 9, 1, 1), "lines"), 62 | legend.position = "none") 63 | 64 | 65 | # Build the plot and get the gtable 66 | rJavaPopularity_GTable <- ggplot_gtable(ggplot_build(p_rJavaPopularity)) 67 | 68 | # Modify the clipping settings 69 | rJavaPopularity_GTable$layout$clip[rJavaPopularity_GTable$layout$name == "panel"] <- "off" 70 | 71 | # Draw the plot 72 | p_rJavaPopularity_filepath <- "vignettes/media/images/rJavaPopularity.svg" 73 | dir.create(dirname(p_rJavaPopularity_filepath), recursive = TRUE) 74 | svg(p_rJavaPopularity_filepath, width = 12, height = 6) 75 | grid::grid.draw(rJavaPopularity_GTable) 76 | dev.off() 77 | 78 | # resmush::resmush_file(p_rJavaPopularity_filepath, overwrite = TRUE) 79 | 80 | p_rJavaPopularity_filepath_pdf <- "vignettes/media/images/rJavaPopularity.pdf" 81 | dir.create(dirname(p_rJavaPopularity_filepath_pdf), recursive = TRUE) 82 | cairo_pdf(p_rJavaPopularity_filepath_pdf, width = 12, height = 6) 83 | grid::grid.draw(rJavaPopularity_GTable) 84 | dev.off() 85 | 86 | 87 | 88 | 89 | 90 | 91 | # individual rJava-dependent packages ------------------------------------- 92 | 93 | p_rJavaDepIndivAll <- rJava_dependants_dlstats_cran |> 94 | ggplot(aes(x = end, y = downloads, group = package, color = package)) + 95 | geom_line(alpha = 0.5) + 96 | scale_x_date(date_breaks = "1 year", date_labels = "%Y") + 97 | scale_y_continuous(labels = scales::label_number()) + 98 | gghighlight(max(downloads), max_highlight = 5L, label_key = package) + 99 | theme_pubclean(base_size = 18) + 100 | labs(title = "Downloads Over Time for Selected Packages", 101 | x = "Date", 102 | y = "Downloads", 103 | color = "Package") 104 | 105 | # Draw the plot 106 | p_rJavaDepIndivAll_filepath <- "vignettes/media/images/rJavaDepIndivAll.svg" 107 | dir.create(dirname(p_rJavaDepIndivAll_filepath), recursive = TRUE) 108 | svg(p_rJavaDepIndivAll_filepath, width = 12, height = 6) 109 | grid::grid.draw(p_rJavaDepIndivAll) 110 | dev.off() 111 | 112 | 113 | # resmush::resmush_file(p_rJavaDepIndivAll_filepath, overwrite = TRUE) 114 | 115 | # top 20 rJava-dependent packages without xlsx ----------------------------------------- 116 | 117 | p_rJavaDepIndivFiltered <- rJava_dependants_dlstats_cran |> 118 | filter(! package %in% c("xlsx", "xlsxjars") ) |> 119 | filter(! grepl("jars$", package)) |> 120 | filter(end >= "2023-09-26") |> 121 | group_by(package) |> 122 | summarise(downloads = sum(downloads, na.rm = T), .groups = "drop") |> 123 | arrange(desc(downloads)) |> 124 | head(20) |> 125 | mutate(package = factor(package, levels = rev(unique(package)))) |> 126 | ggplot(aes(x = downloads, y = package)) + 127 | geom_point() + 128 | geom_segment(aes(x = 0, xend = downloads, y = package, yend = package)) + 129 | scale_x_continuous(labels = scales::label_number()) + 130 | # geom_line(alpha = 0.5) + 131 | # scale_x_date(date_breaks = "1 year", date_labels = "%Y") + 132 | # scale_y_continuous(labels = scales::label_number()) + 133 | # gghighlight(max(downloads), max_highlight = 6L) + 134 | theme_pubclean(base_size = 18) + 135 | labs(title = "Top rJava-based Package Downloads", 136 | subtitle = "Over the Last Year (September 2023 - September 2024)", 137 | x = "Total dowloads", 138 | y = "") 139 | 140 | # Draw the plot 141 | p_rJavaDepIndivFiltered_filepath <- "vignettes/media/images/rJavaDepIndivFiltered.svg" 142 | dir.create(dirname(p_rJavaDepIndivFiltered_filepath), recursive = TRUE) 143 | svg(p_rJavaDepIndivFiltered_filepath, width = 12, height = 6) 144 | grid::grid.draw(p_rJavaDepIndivFiltered) 145 | dev.off() 146 | 147 | 148 | # resmush::resmush_file(p_rJavaDepIndivFiltered_filepath, overwrite = TRUE) 149 | 150 | # top 20 rJava-dependent packages with xlsx ----------------------------------------- 151 | 152 | p_rJavaDepIndivFilteredXslx <- rJava_dependants_dlstats_cran |> 153 | filter(! grepl("jars$", package)) |> 154 | filter(end >= "2023-09-26") |> 155 | group_by(package) |> 156 | summarise(downloads = sum(downloads, na.rm = T), .groups = "drop") |> 157 | arrange(desc(downloads)) |> 158 | head(20) |> 159 | mutate(package = factor(package, levels = rev(unique(package)))) |> 160 | ggplot(aes(x = downloads, y = package)) + 161 | geom_point() + 162 | geom_segment(aes(x = 0, xend = downloads, y = package, yend = package)) + 163 | scale_x_continuous(labels = scales::label_number()) + 164 | # geom_line(alpha = 0.5) + 165 | # scale_x_date(date_breaks = "1 year", date_labels = "%Y") + 166 | # scale_y_continuous(labels = scales::label_number()) + 167 | # gghighlight(max(downloads), max_highlight = 6L) + 168 | theme_pubclean(base_size = 18) + 169 | labs(title = "Top rJava-based Package Downloads", 170 | subtitle = "Over the Last Year (September 2023 - September 2024)", 171 | x = "Total dowloads", 172 | y = "") 173 | 174 | 175 | # Draw the plot 176 | p_rJavaDepIndivFilteredXslx_filepath <- "vignettes/media/images/rJavaDepIndivFilteredXslx.svg" 177 | dir.create(dirname(p_rJavaDepIndivFilteredXslx_filepath), recursive = TRUE) 178 | svg(p_rJavaDepIndivFilteredXslx_filepath, width = 12, height = 6) 179 | grid::grid.draw(p_rJavaDepIndivFilteredXslx) 180 | dev.off() 181 | 182 | 183 | # resmush::resmush_file(p_rJavaDepIndivFiltered_filepath, overwrite = TRUE) 184 | -------------------------------------------------------------------------------- /vignettes/data-for-vignettes/rJava_dlstats.csv: -------------------------------------------------------------------------------- 1 | start;end;downloads;package 2 | 2014-01-01;2014-01-31;21206;rJava 3 | 2014-02-01;2014-02-28;20698;rJava 4 | 2014-03-01;2014-03-31;22972;rJava 5 | 2014-04-01;2014-04-30;30754;rJava 6 | 2014-05-01;2014-05-31;27456;rJava 7 | 2014-06-01;2014-06-30;79683;rJava 8 | 2014-07-01;2014-07-31;68628;rJava 9 | 2014-08-01;2014-08-31;53476;rJava 10 | 2014-09-01;2014-09-30;43039;rJava 11 | 2014-10-01;2014-10-31;42962;rJava 12 | 2014-11-01;2014-11-30;44860;rJava 13 | 2014-12-01;2014-12-31;43873;rJava 14 | 2015-01-01;2015-01-31;47579;rJava 15 | 2015-02-01;2015-02-28;45369;rJava 16 | 2015-03-01;2015-03-31;55592;rJava 17 | 2015-04-01;2015-04-30;59371;rJava 18 | 2015-05-01;2015-05-31;58762;rJava 19 | 2015-06-01;2015-06-30;70761;rJava 20 | 2015-07-01;2015-07-31;77745;rJava 21 | 2015-08-01;2015-08-31;93620;rJava 22 | 2015-09-01;2015-09-30;98996;rJava 23 | 2015-10-01;2015-10-31;105546;rJava 24 | 2015-11-01;2015-11-30;113165;rJava 25 | 2015-12-01;2015-12-31;92368;rJava 26 | 2016-01-01;2016-01-31;116670;rJava 27 | 2016-02-01;2016-02-29;105817;rJava 28 | 2016-03-01;2016-03-31;104942;rJava 29 | 2016-04-01;2016-04-30;91556;rJava 30 | 2016-05-01;2016-05-31;118943;rJava 31 | 2016-06-01;2016-06-30;117215;rJava 32 | 2016-07-01;2016-07-31;106574;rJava 33 | 2016-08-01;2016-08-31;108471;rJava 34 | 2016-09-01;2016-09-30;120946;rJava 35 | 2016-10-01;2016-10-31;134884;rJava 36 | 2016-11-01;2016-11-30;147999;rJava 37 | 2016-12-01;2016-12-31;118118;rJava 38 | 2017-01-01;2017-01-31;123550;rJava 39 | 2017-02-01;2017-02-28;138221;rJava 40 | 2017-03-01;2017-03-31;162562;rJava 41 | 2017-04-01;2017-04-30;153474;rJava 42 | 2017-05-01;2017-05-31;164487;rJava 43 | 2017-06-01;2017-06-30;153560;rJava 44 | 2017-07-01;2017-07-31;143023;rJava 45 | 2017-08-01;2017-08-31;128602;rJava 46 | 2017-09-01;2017-09-30;140409;rJava 47 | 2017-10-01;2017-10-31;177898;rJava 48 | 2017-11-01;2017-11-30;193822;rJava 49 | 2017-12-01;2017-12-31;155733;rJava 50 | 2018-01-01;2018-01-31;165852;rJava 51 | 2018-02-01;2018-02-28;147561;rJava 52 | 2018-03-01;2018-03-31;159540;rJava 53 | 2018-04-01;2018-04-30;159216;rJava 54 | 2018-05-01;2018-05-31;162024;rJava 55 | 2018-06-01;2018-06-30;177379;rJava 56 | 2018-07-01;2018-07-31;158981;rJava 57 | 2018-08-01;2018-08-31;146357;rJava 58 | 2018-09-01;2018-09-30;178890;rJava 59 | 2018-10-01;2018-10-31;222617;rJava 60 | 2018-11-01;2018-11-30;185174;rJava 61 | 2018-12-01;2018-12-31;140504;rJava 62 | 2019-01-01;2019-01-31;171958;rJava 63 | 2019-02-01;2019-02-28;157729;rJava 64 | 2019-03-01;2019-03-31;180216;rJava 65 | 2019-04-01;2019-04-30;226195;rJava 66 | 2019-05-01;2019-05-31;234531;rJava 67 | 2019-06-01;2019-06-30;187438;rJava 68 | 2019-07-01;2019-07-31;193139;rJava 69 | 2019-08-01;2019-08-31;181692;rJava 70 | 2019-09-01;2019-09-30;218554;rJava 71 | 2019-10-01;2019-10-31;224568;rJava 72 | 2019-11-01;2019-11-30;211361;rJava 73 | 2019-12-01;2019-12-31;191373;rJava 74 | 2020-01-01;2020-01-31;188198;rJava 75 | 2020-02-01;2020-02-29;177194;rJava 76 | 2020-03-01;2020-03-31;278531;rJava 77 | 2020-04-01;2020-04-30;235117;rJava 78 | 2020-05-01;2020-05-31;216240;rJava 79 | 2020-06-01;2020-06-30;209888;rJava 80 | 2020-07-01;2020-07-31;234058;rJava 81 | 2020-08-01;2020-08-31;194163;rJava 82 | 2020-09-01;2020-09-30;222106;rJava 83 | 2020-10-01;2020-10-31;241788;rJava 84 | 2020-11-01;2020-11-30;215793;rJava 85 | 2020-12-01;2020-12-31;180348;rJava 86 | 2021-01-01;2021-01-31;168354;rJava 87 | 2021-02-01;2021-02-28;155617;rJava 88 | 2021-03-01;2021-03-31;183883;rJava 89 | 2021-04-01;2021-04-30;178903;rJava 90 | 2021-05-01;2021-05-31;178902;rJava 91 | 2021-06-01;2021-06-30;173072;rJava 92 | 2021-07-01;2021-07-31;141658;rJava 93 | 2021-08-01;2021-08-31;170959;rJava 94 | 2021-09-01;2021-09-30;254287;rJava 95 | 2021-10-01;2021-10-31;274728;rJava 96 | 2021-11-01;2021-11-30;223077;rJava 97 | 2021-12-01;2021-12-31;210562;rJava 98 | 2022-01-01;2022-01-31;192186;rJava 99 | 2022-02-01;2022-02-28;154710;rJava 100 | 2022-03-01;2022-03-31;255524;rJava 101 | 2022-04-01;2022-04-30;571935;rJava 102 | 2022-05-01;2022-05-31;852808;rJava 103 | 2022-06-01;2022-06-30;725289;rJava 104 | 2022-07-01;2022-07-31;639130;rJava 105 | 2022-08-01;2022-08-31;712597;rJava 106 | 2022-09-01;2022-09-30;633770;rJava 107 | 2022-10-01;2022-10-31;433795;rJava 108 | 2022-11-01;2022-11-30;337744;rJava 109 | 2022-12-01;2022-12-31;319878;rJava 110 | 2023-01-01;2023-01-31;403060;rJava 111 | 2023-02-01;2023-02-28;361259;rJava 112 | 2023-03-01;2023-03-31;475392;rJava 113 | 2023-04-01;2023-04-30;442267;rJava 114 | 2023-05-01;2023-05-31;400598;rJava 115 | 2023-06-01;2023-06-30;318804;rJava 116 | 2023-07-01;2023-07-31;176955;rJava 117 | 2023-08-01;2023-08-31;139944;rJava 118 | 2023-09-01;2023-09-30;137718;rJava 119 | 2023-10-01;2023-10-31;280514;rJava 120 | 2023-11-01;2023-11-30;285721;rJava 121 | 2023-12-01;2023-12-31;302552;rJava 122 | 2024-01-01;2024-01-31;328002;rJava 123 | 2024-02-01;2024-02-29;228557;rJava 124 | 2024-03-01;2024-03-31;194654;rJava 125 | 2024-04-01;2024-04-30;187262;rJava 126 | 2024-05-01;2024-05-31;198761;rJava 127 | 2024-06-01;2024-06-30;169666;rJava 128 | 2024-07-01;2024-07-31;148789;rJava 129 | 2024-08-01;2024-08-31;135307;rJava 130 | 2024-09-01;2024-09-26;107725;rJava 131 | -------------------------------------------------------------------------------- /vignettes/multiple-java-with-targets-callr.qmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Multiple `Java` environments in one project with `targets` and `callr`" 3 | vignette: > 4 | %\VignetteIndexEntry{Multiple `Java` environments in one project with `targets` and `callr`} 5 | %\VignetteEngine{quarto::html} 6 | %\VignetteEncoding{UTF-8} 7 | execute: 8 | eval: false 9 | format: 10 | html: 11 | toc: true 12 | toc-depth: 2 13 | code-overflow: wrap 14 | --- 15 | 16 | If you need to use multiple `Java` distribution versions in a single project, you can use a handy shortcut function `use_java()` kindly [suggested by Hadley Wickham](https://github.com/e-kotov/rJavaEnv/issues/44){target='_blank'}. 17 | 18 | Essentialy, `use_java()` does the same thing as `java_quick_install()`, but in a less intrusive way. It downloads the distribution of the user requested major version of `Java`, unpacks it, also to the cache folder, but unlike `java_quick_install()`, it does not copy or link the `Java` installation folder from cache into the project directory and does not create or edit your `.Rprofile` file. Instead, it just sets the environment in the current R script to the requested `Java` binaries in the cache folder. The download and unpacking only happens once, so each next run is practically instant, as the function only needs to set the environment in the current R script. 19 | 20 | # How to use `use_java()` 21 | 22 | Let's illustrate this with a simple example. 23 | 24 | First, load the package and check the valid major versions of `Java`: 25 | 26 | ```{r} 27 | library(rJavaEnv) 28 | java_valid_versions() 29 | ``` 30 | 31 | 32 | ``` 33 | [1] "8" "11" "15" "16" "17" "18" "19" "20" "21" "22" "23" "24" 34 | ``` 35 | 36 | ::: {.callout-note} 37 | The available versions of `Java` depend on your OS and architecture, so you might see a shorter list on your system. 38 | ::: 39 | 40 | Now select any two or three versions and run `use_java()`, checking every time that correct java was set in the current environment. 41 | 42 | ```{r} 43 | use_java("8") 44 | "8" == java_check_version_cmd(quiet = TRUE) 45 | "8" == java_check_version_rjava(quiet = TRUE) 46 | ``` 47 | 48 | ``` 49 | [1] TRUE 50 | [1] TRUE 51 | ``` 52 | 53 | ```{r} 54 | use_java(17) 55 | "17" == java_check_version_cmd(quiet = TRUE) 56 | "17" == java_check_version_rjava(quiet = TRUE) 57 | ``` 58 | 59 | ``` 60 | [1] TRUE 61 | [1] TRUE 62 | ``` 63 | 64 | ```{r} 65 | use_java(21) 66 | "21" == java_check_version_cmd(quiet = TRUE) 67 | "21" == java_check_version_rjava(quiet = TRUE) 68 | ``` 69 | 70 | 71 | ``` 72 | [1] TRUE 73 | [1] TRUE 74 | ``` 75 | 76 | You probably had to wait for a bit for the Java distribution to be downloaded and unpacked. 77 | 78 | However, now if you repeat the same commands, you will see that the correct `Java` version is set instantly, as downloading and unpacking are skipped. 79 | 80 | # How to use with `targets` and `callr` 81 | 82 | Both [`{targets}`](https://docs.ropensci.org/targets/){target="_blank"} and [`{callr}`](https://callr.r-lib.org/){target="_blank"} packages allow the user to run any R scripts in clean separate R sessions. This essentially allows the user to run multiple versions of `Java` in one project with `targets` and `callr`, mostly overcoming the issue of manually switching between `Java` versions in one project. 83 | 84 | One simple thing you can do if one of the scripts needs Java 8, and another one needs Java 17, is to insert `use_java()` in beginning of the scripts that you run through `targets` or `callr` like so: 85 | 86 | ```{r} 87 | library(rJavaEnv) 88 | use_java("17") 89 | ``` 90 | 91 | Or: 92 | 93 | ```{r} 94 | rJavaEnv::use_java("17") 95 | ``` 96 | 97 | 98 | The first run of such script will have to go through the the process of downloading and unpacking the `Java` distribution. The second run will not need to download and unpacking and will be instant. 99 | 100 | If you need the runs to be instant from the first attempt, you can predownload and pre-install `Java` into cache folders using: 101 | 102 | ```{r} 103 | java_17_distrib <- java_download("17") 104 | java_unpack(java_17_distrib) 105 | ``` 106 | -------------------------------------------------------------------------------- /vignettes/rJavaEnv.qmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Quick Start Guide: `Java` Setup for 'R' Projects" 3 | vignette: > 4 | %\VignetteIndexEntry{Quick Start Guide: `Java` Setup for 'R' Projects} 5 | %\VignetteEngine{quarto::html} 6 | %\VignetteEncoding{UTF-8} 7 | execute: 8 | eval: false 9 | format: 10 | html: 11 | toc: true 12 | toc-depth: 2 13 | code-overflow: wrap 14 | --- 15 | 16 | 17 | This guide will walk you through downloading, installing, and managing `Java` environments for your R projects using the `rJavaEnv` package. We'll cover setting up the environment, un-setting it, managing distributions, installing `Java`, and checking `Java` versions. For more advanced use refer to the vignettes on [step-by-step fine-grained procedure to download, unpack, install and linke `Java`](rJavaEnv-step-by-step.qmd) and [vignette on using `rJavaEnv` with the `targets` and `callr` packages to manage multiple `Java` environments](multiple-java-with-targets-callr.qmd) 18 | 19 | ### 1. Quickly Download and Install Java 20 | 21 | #### **Install `rJavaEnv`** 22 | 23 | Install `rJavaEnv` from CRAN: 24 | 25 | 26 | ```{r} 27 | #| eval: false 28 | install.packages("rJavaEnv") 29 | ``` 30 | 31 | 32 | Or install the latest version of `rJavaEnv` from R universe: 33 | 34 | ```{r} 35 | #| eval: false 36 | install.packages('rJavaEnv', 37 | repos = c('https://e-kotov.r-universe.dev', 'https://cloud.r-project.org') 38 | ) 39 | ``` 40 | 41 | 42 | #### **Quick Install `Java` JDK** 43 | 44 | Assume your project directory is currently in a temporary directory. Feel free to skip that, if you are already working in a desired project directory where you would like to install `Java`. In the example outputs below you will see paths that point to a temporary directory, but in a real project you would see your project directory instead. 45 | 46 | ```{r} 47 | project_dir <- tempdir() 48 | setwd(project_dir) 49 | ``` 50 | 51 | The first time you run any function that requires writing into your home space, you will be provided with a prompt warning you that the package may write to the package cache folder in your home directory, to your current project directory, as well as to the .Rprofile file in your project directory (or any directory you specify). 52 | 53 | To quickly install `Java` JDK 21 (which is also default, if not specified) in your current project directory and set the environment: 54 | 55 | ```{r} 56 | library(rJavaEnv) 57 | java_quick_install(version = 21) 58 | ``` 59 | 60 | **On first run, you will be asked for consent to change your environment variables and `.Rprofile` file in the current working/project directory. This only happens once.** 61 | 62 | The command above: 63 | 64 | - Downloads the `Java` distribution compatible with your OS and architecture. 65 | 66 | - Installs `Java` in a cache directory. 67 | 68 | - Sets the `JAVA_HOME` and `PATH` environment variables for the current session and project/working directory, so that any `Java`/`rJava` dependent `R` package can use this requested `Java` version. 69 | 70 | Example expected output (on a Windows machine): 71 | 72 | ``` 73 | Consent has been granted and recorded. 74 | Detected platform: windows 75 | Detected architecture: x64 76 | You can change the platform and architecture by specifying the `platform` and `arch` arguments. 77 | Downloading Java 21 (Corretto) for windows x64 to C:\Users\user_name\AppData\Local/R/cache/R/rJavaEnv/distrib/amazon-corretto-21-x64-windows-jdk.zip 78 | [100%] Downloaded 201696048 bytes... 79 | Download completed. 80 | MD5 checksum verified. 81 | v Current R Session: JAVA_HOME and PATH set to C:\Users\user_name\AppData\Local/R/cache/R/rJavaEnv/installed/windows/x64/21 82 | v Current R Project/Working Directory: JAVA_HOME and PATH set to 'C:\Users\user_name\AppData\Local/R/cache/R/rJavaEnv/installed/windows/x64/21' in .Rprofile at 'C:/Users/user_name/AppData/Local/Temp/75/ 83 | RtmpuoG3xJ' 84 | Java 21 (amazon-corretto-21-x64-windows-jdk.zip) for windows x64 installed at C:\Users\user_name\AppData\Local/R/cache/R/rJavaEnv/installed/windows/x64/21 and symlinked to 85 | C:/Users/user_name/AppData/Local/Temp/75/RtmpuoG3xJ/rjavaenv/windows/x64/21 86 | ``` 87 | 88 | That is it. You can now use your `Java`/`rJava`-dependent `R` package. 89 | 90 | ### 2. **Check `Java` installation** 91 | 92 | You can check if the newly installed `Java` will be correctly picked up by the `Java`/`rJava`-dependent `R` package that you are going to use with. 93 | 94 | For `R` packages that use `Java` via `rJava`-dependency (e.g. [`r5r`](https://github.com/ipeaGIT/r5r){target="_blank"}), you can use the following command: 95 | 96 | ```{r} 97 | java_check_version_rjava() 98 | ``` 99 | 100 | Example expected output (on a Windows machine): 101 | 102 | ``` 103 | Using current session's JAVA_HOME: C:\Users\user_name\AppData\Local/R/cache/R/rJavaEnv/installed/windows/x64/21 104 | With the user-specified JAVA_HOME rJava and other rJava/Java-based packages will use Java version: "21.0.4" 105 | [1] TRUE 106 | ``` 107 | 108 | For `R` packages that use `Java` from command line (e.g. [`opentripplanner`](https://github.com/ropensci/opentripplanner){target="_blank"}), you can use the following command: 109 | 110 | ```{r} 111 | java_check_version_cmd() 112 | ``` 113 | 114 | Example expected output (on a Windows machine): 115 | 116 | ``` 117 | java_check_version_cmd() 118 | JAVA_HOME: C:\Users\user_name\AppData\Local/R/cache/R/rJavaEnv/installed/windows/x64/21 119 | Java path: /c/Users/user_name/AppData/Local/R/cache/R/rJavaEnv/installed/windows/x64/21/bin/java 120 | Java version: "openjdk version \"21.0.4\" 2024-07-16 LTS OpenJDK Runtime Environment Corretto-21.0.4.7.1 (build 21.0.4+7-LTS) OpenJDK 64-Bit Server VM Corretto-21.0.4.7.1 (build 21.0.4+7-LTS, 121 | mixed mode, sharing)" 122 | [1] TRUE 123 | ``` 124 | 125 | 126 | #### Note for Linux users {#note-linux} 127 | Note: if you are on a Linux system that did not have any `Java` version previoulsy installed and you are not using pre-build `R` package binaries (for example from 'Posit Package Manager') and instead install all `R` packages from source, after this step you may have to quit `R`, [follow these steps](https://solutions.posit.co/envs-pkgs/using-rjava/#reconfigure-r){target='_blank'} to set configure `Java` for `R`, and only then install `rJava`, as otherwise `rJava` cannot be built from source.* 128 | 129 | ### 3. Return things to their original state 130 | 131 | 132 | #### Unset `Java` 133 | 134 | Run the following code to unset the `Java` for the current working directory: 135 | 136 | ```{r} 137 | java_env_unset() 138 | ``` 139 | 140 | Example expected output (on a Windows machine): 141 | 142 | ``` 143 | Removed JAVA_HOME settings from .Rprofile in 'C:/Users/user_name/AppData/Local/Temp/75/RtmpuoG3xJ/.Rprofile' 144 | ``` 145 | 146 | 147 | 148 | #### Delete `Java` from the project directory 149 | 150 | The line below clears all `Java` installations in the project directory: 151 | 152 | ```{r} 153 | java_clear("project", delete_all = TRUE) 154 | ``` 155 | 156 | 157 | Example expected output: 158 | 159 | ``` 160 | All Java symlinks in the project have been cleared. 161 | ``` 162 | 163 | Now restart the current `R` session so that `R` picks up the system `Java` (or no `Java`, if it is not installed in the system). 164 | 165 | ### 4. Complete Cleanup 166 | 167 | If you do not want to use `rJavaEnv` anymore, please clear the cache folders before removing the package: 168 | 169 | ```{r} 170 | java_clear("project", delete_all = TRUE) 171 | java_clear("installed", delete_all = TRUE) 172 | java_clear("distrib", delete_all = TRUE) 173 | ``` 174 | 175 | Also, clear the `.Rprofile` file in the projects there you used the package: 176 | 177 | ```{r} 178 | java_env_unset() 179 | ``` 180 | 181 | 182 | Now you can remove the package and restart the current `R` session so that `R` picks up the system `Java` (or no `Java`, if it is not installed in the system). 183 | -------------------------------------------------------------------------------- /vignettes/why-rJavaEnv.qmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Why rJavaEnv: the landscape of 'Java'-dependent R packages" 3 | vignette: > 4 | %\VignetteIndexEntry{Why rJavaEnv: the landscape of 'Java'-dependent R packages} 5 | %\VignetteEngine{quarto::html} 6 | %\VignetteEncoding{UTF-8} 7 | bibliography: [bibliography.bib] 8 | format: 9 | html: 10 | toc: true 11 | toc-depth: 2 12 | code-overflow: wrap 13 | --- 14 | 15 | 16 | # Overall popularity of Java-dependent R packages 17 | 18 | While not as popular as widely known and highly popular ggplot2 and data.table packages, and rJava-dependent packages (104 on CRAN and another 14 on Bioconductor) (and consequently, rJava itself ) are widely used in the R community (see @fig-rJavaPopularity). The rJava [@rjava] itself was downloaded 107,725 times in September, 2024. The total number of downloads for rJava-dependent packages was 178,185 on CRAN and 3,565 on Bioconductor. To put this into context, ggplot2 was downloaded 1,329,676 times and data.table was downloaded 729,796 times in September, 2024. So rJava-based packages collectively are 7.5 times less popular than ggplot2, but they have a noticeable number of users. 19 | 20 | ![CRAN Downloads Over Time for rJava and rJava-dependent Packages, compared to popular ggplot2 and data.table for context](media/images/rJavaPopularity.svg){#fig-rJavaPopularity width="100%"} 21 | 22 | Note that the analysis above only covers packages that are available on CRAN and Bioconductor and only those that explicitly depend on the `rJava` package. There are other packages that use `Java` but do not depend on the `rJava` package. For example, the [`{opentripplanner}`](https://github.com/ropensci/opentripplanner){target="_blank"} package also relies on underlying Java-based software but calls it from the command line. This, however, also requires system environment variables to be set up correctly. 23 | 24 | Identifying packages such as `opentripplanner` is more complicated, as they do not have a direct dependency on the `rJava` package. We can assume that there are not as many of them compared to those that depend on `rJava.` 25 | 26 | 27 | # Individual Java-dependent packages 28 | 29 | If we zoom in to the individual `rJava`-dependent packages, we will see in @fig-rJavaDepIndivAll, that most downloads are generated by `xlsx` and its "companion" `xlsxjars`. 30 | 31 | ![CRAN Downloads Over Time for all rJava-dependent Packages](media/images/rJavaDepIndivAll.png){#fig-rJavaDepIndivAll width="100%"} 32 | 33 | If we remove `xlsx` (and `xlsxjars`) as an outlier, we will see in @fig-rJavaDepIndivFiltered), that top packages are: 34 | 35 | - [`r5r`](https://github.com/ipeaGIT/r5r){target="_blank"} for *"rapid realistic routing on multimodal transport networks (walk, bike, public transport and car)"* [@pereira_r5r_2021]. The package users experience multiple issues with Java and report them on GitHub, just few examples include [1](https://github.com/ipeaGIT/r5r/issues/372){target="_blank"}, [2](https://github.com/ipeaGIT/r5r/issues/374){target="_blank"}, [3](https://github.com/ipeaGIT/r5r/issues/338){target="_blank"} and [many more](https://github.com/ipeaGIT/r5r/issues){target="_blank"}. 36 | 37 | - [`RJDBC`](https://www.rforge.net/RJDBC/){target="_blank"} that *"[p]rovides Access to Databases Through the JDBC Interface"* [@rjdbc]. I was not able to find a bug tracker for this package, but a simple web search reveals multiple issues such as [this one](https://stackoverflow.com/questions/45338197/r-cannot-find-java-home-when-using-java-jdk-1-8-rjava-wont-work){target="_blank"} on StackOverflow. 38 | 39 | - [`mailR`](https://github.com/rpremrajGit/mailR){target="_blank"} for *"send[ing] emails from R"* [@mailr] (has a Java related [issue](https://github.com/rpremrajGit/mailR/issues/9){target="_blank"} on GitHub). Web search also reveals StackOverflow [discussions](https://stackoverflow.com/questions/61871960/r-mailr-package-not-loading-java){target="_blank"} related to Java version issues. 40 | 41 | - [`RWeka`](https://doi.org/10.32614/CRAN.package.RWeka){target="_blank"}, R interface to Weka. Weka itself *"is a collection of machine learning algorithms for data mining tasks written in Java*" [@rweka]. StackOverflow [discussions](https://stackoverflow.com/questions/40752070/issues-installing-rweka){target="_blank"} related to Java version issues. 42 | 43 | 44 | ![CRAN Downloads Over Time for top 20 rJava-dependent Packages](media/images/rJavaDepIndivFiltered.png){#fig-rJavaDepIndivFiltered width="100%"} 45 | 46 | Some other packages: 47 | 48 | - [`openNLP`](https://doi.org/10.32614/CRAN.package.openNLP){target="_blank"}. *"OpenNLP library is a machine learning based toolkit for the processing of natural language text written in Java"* [@opennlp]. It also has Java related issues [discussed](https://stackoverflow.com/questions/37014340/installing-r-package-opennlp-in-r){target="_blank"} on StackOverflow. 49 | 50 | - [`xlsx`](https://github.com/colearendt/xlsx){target="_blank"}. *"An R package to interact with Excel files using the Apache POI [J]ava library"* [@xlsx]. Also many discussions on both [StackOverflow](https://stackoverflow.com/questions/62012760/r-xlsx-package-can-not-be-used){target="_blank"} and [GitHub](https://github.com/colearendt/xlsx/issues/183){target="_blank"}. 51 | 52 | 53 | To summarize, regardless of the Java-dependent R package being used, users consistently encounter issues with having the correct Java runtime installed on their system. Additionally, they may be using various R packages that depend on different Java versions, complicating the management of Java environment variables. This task is particularly challenging for ordinary users who simply want to get their analysis running smoothly and efficiently. 54 | 55 | # `rJavaEnv` R package as a solution 56 | 57 | `rJavaEnv` aims to assist users of all `Java`/`rJava`-dependent packages by providing functions to quickly install the required `Java` version and set environment variables. This ensures that the packages the user plans to use pick up the correct Java version with minimal intervention to the user's system. Compared to manually downloading `Java` from Oracle, Amazon, or another vendor and installing it using the installer, `rJavaEnv` downloads non-installer archives of `Java`, extracts them to a cache folder, and links them in the current project or working directory. This way, `rJavaEnv` does not contaminate the user's machine with unnecessary installations and configurations. 58 | 59 | Furthermore, `rJavaEnv` streamlines the process, allowing users to focus on their analysis without worrying about complex `Java` setup issues. By automating these tasks, `rJavaEnv` reduces the potential for errors and ensures a smoother experience for users who need to manage multiple Java-dependent R packages. 60 | 61 | # References 62 | 63 | ::: {#refs} 64 | ::: 65 | --------------------------------------------------------------------------------