Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

add dot_to_package fn like rprojroot #305

Merged
merged 4 commits into from
May 10, 2021
Merged

add dot_to_package fn like rprojroot #305

merged 4 commits into from
May 10, 2021

Conversation

mpadge
Copy link
Member

@mpadge mpadge commented Feb 16, 2021

This enables write_codemetar to be called from anywhere within a package directory structure. It is essentially a hard-coded version of what rprojroot does to locate the root of an R package. Pretty sure it has no effects on anything else, as it's only evoked when pkg = ".".

library(codemetar) # current version prior to this PR
setwd (<path>/<to>/<local>/<codemetar>)
setwd("./R")

write_codemeta()
#> Error: File `./DESCRIPTION' does not exist

That's annoying because it does exist! With this PR:

devtools::load_all (".", export_all = FALSE) # Version with this PR
#> Loading codemetar
write_codemeta()
#> … Getting CRAN metadata from RStudio CRAN mirror
#> ✔ Got CRAN metadata!
#> codemetar has the highest opinion of this R package :-)
#> … Getting Bioconductor metadata
#> ✔ Got Bioconductor metadata!
#> … Getting sysreqs URL from sysreqs API
#> ✔ Got sysreqs URL from sysreqs API!
#> … Asking README URL from GitHub API
#> ✔ Got README URL!
#> … Asking README URL from GitHub API
#> ✔ Got README URL!
#> … Getting repo topics from GitHub API
#> ✔ Got repo topics!

Created on 2021-02-16 by the reprex package (v1.0.0)

That's better!

@maelle maelle requested a review from cboettig February 16, 2021 12:40
@mpadge
Copy link
Member Author

mpadge commented Feb 24, 2021

@cboettig You're like going to have to opine here somewhere, because this PR attempts to make functionality less strictly dependent on exact pkg location, but you comment in #303 about overloading the pkg argument. I'm not sure what you mean there, since the is_package function is just

  all(c("DESCRIPTION", "NAMESPACE", "man", "R") %in% dir(path))  # where `path` is passed as `pkg`

That's clearly only looking for source directories, and is not overloaded. So to the extent that it is not, I would suggest you might be best off first merging this PR, then getting @ThierryO to extend PR #303 to ensure that the pkg argument is "taken into account" for all functions. If, on the other hand, pkg is actually overloaded elsewhere, then you'll need to do some deeper thinking about reconciling these two issues.

Copy link
Member

@maelle maelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a ton @mpadge! This sounds like an useful feature.

Can you make the PR to dev?

# dot_to_package: convert pkg = "." to proper package path ------------------
dot_to_package <- function(pkg = ".") {

# https://github.com/r-lib/rprojroot/blob/master/R/root.R#L115:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add rprojroot as a dependency? We'd still be under 20 Imports.

R/write_codemeta.R Outdated Show resolved Hide resolved
tests/testthat/test-utils.R Outdated Show resolved Hide resolved
tests/testthat/test-utils.R Outdated Show resolved Hide resolved
@maelle maelle changed the base branch from master to dev May 10, 2021 08:31
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 this pull request may close these issues.

2 participants