Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to generate an renv lockfile to go with a reprex #313

Closed
wlandau opened this issue Feb 20, 2020 · 8 comments
Closed

Option to generate an renv lockfile to go with a reprex #313

wlandau opened this issue Feb 20, 2020 · 8 comments

Comments

@wlandau
Copy link

wlandau commented Feb 20, 2020

When I troubleshoot someone else's bug report, I sometimes need to manually install the users's versions of packages listed in the session info (recent example here). Would it be reasonable for reprex() to help automate this process, possibly by supplying an renv lockfile inline in a <details> tag in the output R Markdown?

This is somewhat related to #284 except the relevent reprexes here are not necessarily powered by renv to start.

@wlandau wlandau changed the title Optionally generate an renv lockfile to go with a reprex Option to generate an renv lockfile to go with a reprex Feb 20, 2020
@jennybc
Copy link
Member

jennybc commented Feb 20, 2020

Interesting idea! cc @kevinushey

@kevinushey
Copy link

This sounds like it could be useful. Do we want the lockfile to capture all of the packages in the user's library, or only the ones actually used in the reprex?

One downside is that the renv.lock lockfile can grow fairly large when a large number of packages are installed. In that case, it might be better to instead upload the lockfile renv.lock somewhere (maybe as a gist?) and then paste a link into the generated reprex report.

@wlandau
Copy link
Author

wlandau commented Feb 21, 2020

Do we want the lockfile to capture all of the packages in the user's library, or only the ones actually used in the reprex?

My first thoughts:

  1. Packages that end up actually loaded/attached by the time the reprex finishes running.
  2. Any additional packages renv detects with static code analysis.
  3. Upstream dependencies of (1) and (2).

Are we likely to miss anything that way? If we have (1), do we need (2)?

One downside is that the renv.lock lockfile can grow fairly large when a large number of packages are installed. In that case, it might be better to instead upload the lockfile renv.lock somewhere (maybe as a gist?) and then paste a link into the generated reprex report.

Seems like remote lockfiles would accommodate most use cases, but we use proprietary packages in my work environment, and I need to avoid disclosing internal names and URLs. Related: #214. Could we allow both options?

@jennybc
Copy link
Member

jennybc commented Jan 15, 2021

I've decided I'm not willing to maintain this sort of feature right now. I'm not convinced it will be used intensely enough to justify the addition. As a compromise / workaround, could those who want this craft some sort of code snippet that a user could drop into their reprex, when you really want a lock file, on a ad hoc basis? Then we could have a mini article about it and at least it would be documented in a place easy to point to.

@jennybc jennybc closed this as completed Jan 15, 2021
@kevinushey
Copy link

I can add a function to renv that users could call to dump the contents of a lockfile, to be used at the end of a reprex script.

@kevinushey
Copy link

@jennybc: could reprex also set the target venue, e.g. as an R option, so that add-ons that want to generate reprex-compatible output can query that and tweak output if necessary? This could be queried via something like:

getOption("reprex.venue")

@kevinushey
Copy link

And I've now updated the development version of renv with this -- use

renv::snapshot(reprex = TRUE)

as part of a script that you'd like to include a lockfile for, and the lockfile will be included (as JSON) in the rendered output.

jennybc added a commit that referenced this issue Jan 16, 2021
@jennybc
Copy link
Member

jennybc commented Jan 16, 2021

As of a4e3efe, when any reprex is rendered, you can now do getOption("reprex.current_venue") to find out the venue currently "in force".

Why does the option have this name? We already had an option named reprex.venue, which has a different purpose. It controls the overall default venue for a user, which only affects the reprex_selection() addin. But this is why I had to fiddle with the name a bit.

I have already demo'd this with the dev version of renv! I think this it's a pretty interesting mechanism for synergy between reprex and packages that want to generate specific diagnostics or other artefacts on the user's system. Just to link all this up, here's where @kevinushey did what he describes above: rstudio/renv@25be944. Presumably there will be some refinement now that the reprex.current_venue option exists (you can count on it in reprex >= v1.0.0, which I plan to release soon).

Here's the reprex source:

x <- 1:5
mean(x)

renv::snapshot(reprex = TRUE)

And here's what that produces:

x <- 1:5
mean(x)
#> [1] 3

renv::snapshot(reprex = TRUE)
Lockfile
{
  "R": {
    "Version": "4.0.2",
    "Repositories": [
      {
        "Name": "CRAN",
        "URL": "https://cloud.r-project.org"
      }
    ]
  },
  "Packages": {
    "R6": {
      "Package": "R6",
      "Version": "2.5.0",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "b203113193e70978a696b2809525649d"
    },
    "assertthat": {
      "Package": "assertthat",
      "Version": "0.2.1",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "50c838a310445e954bc13f26f26a6ecf"
    },
    "base64enc": {
      "Package": "base64enc",
      "Version": "0.1-3",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "543776ae6848fde2f48ff3816d0628bc"
    },
    "callr": {
      "Package": "callr",
      "Version": "3.5.1",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "b7d7f1e926dfcd57c74ce93f5c048e80"
    },
    "cli": {
      "Package": "cli",
      "Version": "2.2.0",
      "Source": "CRAN",
      "Repository": "CRAN",
      "RemoteType": "standard",
      "RemotePkgRef": "cli",
      "RemoteRef": "cli",
      "RemoteRepos": "https://cloud.r-project.org",
      "RemotePkgType": "macos",
      "RemoteSha": "2.2.0",
      "Hash": "3ef298932294b775fa0a3eeaa3a645b0"
    },
    "clipr": {
      "Package": "clipr",
      "Version": "0.7.1",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "ebaa97ac99cc2daf04e77eecc7b781d7"
    },
    "crayon": {
      "Package": "crayon",
      "Version": "1.3.4.9000",
      "Source": "GitHub",
      "RemoteType": "github",
      "RemoteHost": "api.github.com",
      "RemoteRepo": "crayon",
      "RemoteUsername": "r-lib",
      "RemotePkgRef": "r-lib/crayon",
      "RemoteRef": "HEAD",
      "RemoteSha": "7679d0f069818ecb6e710e04ec28edf56444055f",
      "Hash": "9c77334d80a7f0393e1d7f2ef4ac9c1a"
    },
    "digest": {
      "Package": "digest",
      "Version": "0.6.27",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "a0cbe758a531d054b537d16dff4d58a1"
    },
    "evaluate": {
      "Package": "evaluate",
      "Version": "0.14",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "ec8ca05cffcc70569eaaad8469d2a3a7"
    },
    "fansi": {
      "Package": "fansi",
      "Version": "0.4.1",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "7fce217eaaf8016e72065e85c73027b5"
    },
    "fs": {
      "Package": "fs",
      "Version": "1.5.0",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "44594a07a42e5f91fac9f93fda6d0109"
    },
    "glue": {
      "Package": "glue",
      "Version": "1.4.2",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "6efd734b14c6471cfe443345f3e35e29"
    },
    "highr": {
      "Package": "highr",
      "Version": "0.8",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "4dc5bb88961e347a0f4d8aad597cbfac"
    },
    "htmltools": {
      "Package": "htmltools",
      "Version": "0.5.0.9003",
      "Source": "GitHub",
      "RemoteType": "github",
      "RemoteHost": "api.github.com",
      "RemoteRepo": "htmltools",
      "RemoteUsername": "rstudio",
      "RemoteRef": "HEAD",
      "RemoteSha": "c2335509e378c3402e805382e384139a17bde0b0",
      "Hash": "2d14b644f570e4ee15742661062a3bea"
    },
    "jsonlite": {
      "Package": "jsonlite",
      "Version": "1.7.2",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "98138e0994d41508c7a6b84a0600cfcb"
    },
    "knitr": {
      "Package": "knitr",
      "Version": "1.30",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "eed7ee0d02eee88d53881cdc92457c62"
    },
    "magrittr": {
      "Package": "magrittr",
      "Version": "2.0.1",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "41287f1ac7d28a92f0a286ed507928d3"
    },
    "markdown": {
      "Package": "markdown",
      "Version": "1.1",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "61e4a10781dd00d7d81dd06ca9b94e95"
    },
    "mime": {
      "Package": "mime",
      "Version": "0.9",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "e87a35ec73b157552814869f45a63aa3"
    },
    "processx": {
      "Package": "processx",
      "Version": "3.4.5",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "22aab6098cb14edd0a5973a8438b569b"
    },
    "ps": {
      "Package": "ps",
      "Version": "1.5.0",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "ebaed51a03411fd5cfc1e12d9079b353"
    },
    "renv": {
      "Package": "renv",
      "Version": "0.12.5-9",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "c19d76cb135b52d3beaf8049bafd1e49"
    },
    "reprex": {
      "Package": "reprex",
      "Version": "0.3.0.9001",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "1e2e7c9356fe22a71de8c38d6e15dffe"
    },
    "rlang": {
      "Package": "rlang",
      "Version": "0.4.10",
      "Source": "GitHub",
      "RemoteType": "github",
      "RemoteHost": "api.github.com",
      "RemoteRepo": "rlang",
      "RemoteUsername": "r-lib",
      "RemoteRef": "HEAD",
      "RemoteSha": "f0c9be5c5806b4e4b120b7516f286fef3c66bda5",
      "Hash": "fe335f772af2d548d7afebbf6609c44d"
    },
    "rmarkdown": {
      "Package": "rmarkdown",
      "Version": "2.6",
      "Source": "CRAN",
      "Repository": "CRAN",
      "RemoteType": "standard",
      "RemotePkgRef": "rmarkdown",
      "RemoteRef": "rmarkdown",
      "RemoteRepos": "https://cloud.r-project.org",
      "RemotePkgType": "macos",
      "RemoteSha": "2.6",
      "Hash": "bc4bac38960b446c183957bfd563e763"
    },
    "stringi": {
      "Package": "stringi",
      "Version": "1.5.3",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "a063ebea753c92910a4cca7b18bc1f05"
    },
    "stringr": {
      "Package": "stringr",
      "Version": "1.4.0",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "0759e6b6c0957edb1311028a49a35e76"
    },
    "tinytex": {
      "Package": "tinytex",
      "Version": "0.28",
      "Source": "CRAN",
      "Repository": "CRAN",
      "RemoteType": "standard",
      "RemotePkgRef": "tinytex",
      "RemoteRef": "tinytex",
      "RemoteRepos": "https://cloud.r-project.org",
      "RemotePkgType": "macos",
      "RemoteSha": "0.28",
      "Hash": "ff73961a77fba606fbf944dc3468e5b9"
    },
    "withr": {
      "Package": "withr",
      "Version": "2.3.0",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "7307d79f58d1885b38c4f4f1a8cb19dd"
    },
    "xfun": {
      "Package": "xfun",
      "Version": "0.20",
      "Source": "CRAN",
      "Repository": "CRAN",
      "RemoteType": "standard",
      "RemotePkgRef": "xfun",
      "RemoteRef": "xfun",
      "RemoteRepos": "https://cloud.r-project.org",
      "RemotePkgType": "macos",
      "RemoteSha": "0.20",
      "Hash": "d7222684dc02327871e3b1da0aba7089"
    },
    "yaml": {
      "Package": "yaml",
      "Version": "2.2.1",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "2826c5d9efb0a88f657c7a679c7106db"
    }
  }
}

Lockfile generated by renv 0.12.5-9.

Created on 2021-01-15 by the reprex package (v0.3.0.9001)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants