Search code examples
rdevtools

R: How can I install a specific release by install_github()?


If the current version of a package, gives some errors, users may prefer to install a specific release (e.g. version 1.0.1). What kind of R code can be used to achieve that?

Take for example for the release of the latest OhdsiRTools R packages:

https://github.com/OHDSI/OhdsiRTools/tree/v1.0.1

The command something like:

install_github("OHDSI/OhdsiRTools", ref = 'v1.0.1')

The code above is not correct. It only works for branches (e.g., master or devA). But the devtools package has functions to refer to releases.

Ideally I would refer to releases by their tag (but solution with commit ID would work too).

EXTRA BONUS: What code can install "latest" release. (but consider this a bonus question. The question about is the main one)


Solution

  • You need to append tags for releases directly onto the name of the repository argument. So, username/repo@releasetag will work. Only use the parameter ref = "devA" when you need to refer to a specific branch of the git repository.

    For your example, regarding OhdsiRTools v1.0.1, we have

    we have:

    devtools::install_github("OHDSI/[email protected]")
    

    Edit

    After toying around with devtools source, it has come to my attention that one can request the latest source with:

    username/repo@*release
    

    Hence, you could use:

    devtools::install_github("OHDSI/OhdsiRTools@*release")
    

    End Edit

    Outdated, see edit

    Unfortunately, to obtain the latest release tag, the work for that is a bit more complicated as it would involve parsing a response from the GitHub API. Here are some notes if you really do need the tagged version... You would have to parse JSON from:

    https://api.github.com/repos/<user>/<repo>/releases/latest
    

    using either RJSONIO, jsonlite, rjson

    To extract "tag_name" from:

    {
      "url": "https://api.github.com/repos/OHDSI/OhdsiRTools/releases/2144150",
      "assets_url": "https://api.github.com/repos/OHDSI/OhdsiRTools/releases/2144150/assets",
      "upload_url": "https://uploads.github.com/repos/OHDSI/OhdsiRTools/releases/2144150/assets{?name,label}",
      "html_url": "https://github.com/OHDSI/OhdsiRTools/releases/tag/v1.0.1",
      "id": 2144150,
      "tag_name": "v1.0.1",
      "target_commitish": "master",
      "name": "Minor bug fix",
      "draft": false,
      "author": {
        "login": "schuemie",
        "id": 6713328,
        "avatar_url": "https://avatars.githubusercontent.com/u/6713328?v=3",
        "gravatar_id": "",
        "url": "https://api.github.com/users/schuemie",
        "html_url": "https://github.com/schuemie",
        "followers_url": "https://api.github.com/users/schuemie/followers",
        "following_url": "https://api.github.com/users/schuemie/following{/other_user}",
        "gists_url": "https://api.github.com/users/schuemie/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/schuemie/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/schuemie/subscriptions",
        "organizations_url": "https://api.github.com/users/schuemie/orgs",
        "repos_url": "https://api.github.com/users/schuemie/repos",
        "events_url": "https://api.github.com/users/schuemie/events{/privacy}",
        "received_events_url": "https://api.github.com/users/schuemie/received_events",
        "type": "User",
        "site_admin": false
      },
      "prerelease": false,
      "created_at": "2015-11-18T00:55:28Z",
      "published_at": "2015-11-18T06:35:57Z",
      "assets": [
    
      ],
      "tarball_url": "https://api.github.com/repos/OHDSI/OhdsiRTools/tarball/v1.0.1",
      "zipball_url": "https://api.github.com/repos/OHDSI/OhdsiRTools/zipball/v1.0.1",
      "body": "Fixed bug in `convertArgsToList ` function."
    }
    

    Above is taken from https://api.github.com/repos/OHDSI/OhdsiRTools/releases/latest