rstudio / rstudioapi

Safely access RStudio's API (when available)
http://rstudio.github.io/rstudioapi
Other
165 stars 35 forks source link

writeRStudioPreference produces invalid cran_mirror entries #220

Open ghost opened 3 years ago

ghost commented 3 years ago

When using writeRStudioPreference to set cran_mirror, all scalar values are encoded as lists in the underlying rstudio-prefs.json, which RStudio doesn't seem to like.

For example, running

rstudioapi::writeRStudioPreference(
  name = "cran_mirror",
  value = list(
    name = "Global (CDN)",
    host = "RStudio",
    url = "https://cran.rstudio.com/",
    repos = "",
    country = "us"
  )
)

produces this entry rstudio-prefs.json:

    "cran_mirror": {
        "name": [
            "Global (CDN)"
        ],
        "host": [
            "RStudio"
        ],
        "url": [
            "https://cran.rstudio.com/"
        ],
        "repos": [
            ""
        ],
        "country": [
            "us"
        ]
    }

RStudio, immediately produces a warning:

WARNING: Your CRAN mirror is set to "" which has an insecure (non-HTTPS) URL. You should either switch to a repository that supports HTTPS or change your RStudio options to not require HTTPS downloads.

To learn more and/or disable this warning message see the "Use secure download method for HTTP" option in Tools -> Global Options -> Packages.
WARNING: Your CRAN mirror is set to "" which has an insecure (non-HTTPS) URL. You should either switch to a repository that supports HTTPS or change your RStudio options to not require HTTPS downloads.

To learn more and/or disable this warning message see the "Use secure download method for HTTP" option in Tools -> Global Options -> Packages.

When the value includes an entry for a secondary repository, RStudio's preferences pane can no longer be opened.

kevinushey commented 3 years ago

Thanks for the bug report. As a workaround, you can force these to be set as scalars with the I() function; e.g.

rstudioapi::writeRStudioPreference(
  name = "cran_mirror",
  value = list(
    name = I("Global (CDN)"),
    host = I("RStudio"),
    url = I("https://cran.rstudio.com/"),
    repos = I(""),
    country = I("us")
  )
)
ghost commented 3 years ago

Thanks! The I() workaround doesn't seem to do the trick for me. Running the above code results in the same JSON. I also got crazy and tried a few permutations like applying I to the whole list object.

rstudioapi 0.13 RStudio 1.4.1103 R 4.0.4