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

Don't include CRAN install instructions to start #1507

Merged
merged 15 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Suggests:
roxygen2,
spelling (>= 1.2),
styler (>= 1.2.0),
testthat (>= 3.0.2)
testthat (>= 3.1.0)
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ usethis has a more sophisticated understanding of the default branch and gains s

* `use_tidy_labels()` has been renamed to `use_tidy_github_labels()` (#1430).

* `use_readme_[r]?md()` no longer includes CRAN install instructions in the
initial template; instead, we only include GitHub-based install instructions or otherwise prompt the user to update instructions (#1507).

# usethis 2.0.1

* All functions that require a package now ask you if you'd like to install it.
Expand Down
20 changes: 17 additions & 3 deletions R/readme.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ use_readme_rmd <- function(open = rlang::is_interactive()) {
return(invisible(FALSE))
}

if (is_pkg && !data$on_github) {
ui_todo("
Update {ui_path('README.Rmd')} to include installation instructions.")
}

if (uses_git()) {
use_git_hook(
"pre-commit",
Expand All @@ -67,17 +72,26 @@ use_readme_rmd <- function(open = rlang::is_interactive()) {
use_readme_md <- function(open = rlang::is_interactive()) {
check_is_project()
is_pkg <- is_package()
repo_spec <- tryCatch(target_repo_spec(ask = FALSE), error = function(e) NULL)
nm <- if (is_pkg) "Package" else "Project"
data <- list2(
!!nm := project_name(),
Rmd = FALSE,
on_github = NULL,
github_spec = NULL
on_github = !is.null(repo_spec),
github_spec = repo_spec
)
use_template(

new <- use_template(
if (is_pkg) "package-README" else "project-README",
"README.md",
data = data,
open = open
)

if (is_pkg && !data$on_github) {
ui_todo("
Update {ui_path('README.md')} to include installation instructions.")
}

invisible(new)
}
2 changes: 1 addition & 1 deletion R/release.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ release_checklist <- function(version, on_cran) {
"",

todo("`usethis::use_cran_comments()`"),
todo("Update (aspirational) install instructions in README"),
Copy link
Member

Choose a reason for hiding this comment

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

I think one should revise the README to be (or at least include) install.packages() at the time of CRAN submission, because hopefully that will soon be true and that's what you want baked into the README on CRAN.

todo("Proofread `Title:` and `Description:`"),
todo("Check that all exported functions have `@return` and `@examples`"),
todo("Check that `Authors@R:` includes a copyright holder (role 'cph')"),
Expand Down Expand Up @@ -116,7 +117,6 @@ release_checklist <- function(version, on_cran) {
todo("`usethis::use_github_release()`"),
todo("`usethis::use_dev_version()`"),
todo("`usethis::use_news_md()`", !has_news),
todo("Update install instructions in README", !on_cran),
todo("Finish blog post", type != "patch"),
todo("Tweet", type != "patch"),
todo("Add link to blog post in pkgdown news menu", type != "patch")
Expand Down
18 changes: 10 additions & 8 deletions inst/templates/package-README
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@ The goal of {{{ Package }}} is to ...

## Installation

You can install the released version of {{{ Package }}} from [CRAN](https://CRAN.R-project.org) with:

``` r
install.packages("{{{ Package }}}")
```

{{#on_github}}
And the development version from [GitHub](https://github.com/) with:
You can install the development version of {{{ Package }}} from [GitHub](https://github.com/) with:

``` r
# install.packages("devtools")
devtools::install_github("{{{ github_spec }}}")
```
{{/on_github}}
{{^on_github}}
You can install the development version of {{{ Package }}} like so:

``` r
# FILL THIS IN! HOW CAN PEOPLE INSTALL YOUR DEV PACKAGE?
```
{{/on_github}}

## Example

This is a basic example which shows you how to solve a common problem:
Expand All @@ -58,7 +60,7 @@ What is special about using `README.Rmd` instead of just `README.md`? You can in
summary(cars)
```

You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-date. `devtools::build_readme()` is handy for this. You could also use GitHub Actions to re-render `README.Rmd` every time you push. An example workflow can be found here: <https://github.com/r-lib/actions/tree/master/examples>.
You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-date. `devtools::build_readme()` is handy for this. You could also use GitHub Actions to re-render `README.Rmd` every time you push. An example workflow can be found here: <https://github.com/r-lib/actions/tree/v1/examples>.

You can also embed plots, for example:

Expand Down
2 changes: 1 addition & 1 deletion inst/templates/project-README
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ What is special about using `README.Rmd` instead of just `README.md`? You can in
summary(cars)
```

You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-date. `devtools::build_readme()` is handy for this. You could also use GitHub Actions to re-render `README.Rmd` every time you push. An example workflow can be found here: <https://github.com/r-lib/actions/tree/master/examples>.
You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-date. `devtools::build_readme()` is handy for this. You could also use GitHub Actions to re-render `README.Rmd` every time you push. An example workflow can be found here: <https://github.com/r-lib/actions/tree/v1/examples>.

You can also embed plots, for example:

Expand Down
184 changes: 184 additions & 0 deletions tests/testthat/_snaps/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# use_readme_md() has expected form for a non-GitHub package

Code
writeLines(read_utf8("README.md"))
Output

# {TESTPKG}

<!-- badges: start -->
<!-- badges: end -->

The goal of {TESTPKG} is to ...

## Installation

You can install the development version of {TESTPKG} like so:

``` r
# FILL THIS IN! HOW CAN PEOPLE INSTALL YOUR DEV PACKAGE?
```

## Example

This is a basic example which shows you how to solve a common problem:

``` r
library({TESTPKG})
## basic example code
```


# use_readme_md() has expected form for a GitHub package

Code
writeLines(read_utf8("README.md"))
Output

# {TESTPKG}

<!-- badges: start -->
<!-- badges: end -->

The goal of {TESTPKG} is to ...

## Installation

You can install the development version of {TESTPKG} from [GitHub](https://github.com/) with:

``` r
# install.packages("devtools")
devtools::install_github("OWNER/TESTPKG")
```

## Example

This is a basic example which shows you how to solve a common problem:

``` r
library({TESTPKG})
## basic example code
```


# use_readme_rmd() has expected form for a non-GitHub package

Code
writeLines(read_utf8("README.Rmd"))
Output
---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# {TESTPKG}

<!-- badges: start -->
<!-- badges: end -->

The goal of {TESTPKG} is to ...

## Installation

You can install the development version of {TESTPKG} like so:

``` r
# FILL THIS IN! HOW CAN PEOPLE INSTALL YOUR DEV PACKAGE?
```

## Example

This is a basic example which shows you how to solve a common problem:

```{r example}
library({TESTPKG})
## basic example code
```

What is special about using `README.Rmd` instead of just `README.md`? You can include R chunks like so:

```{r cars}
summary(cars)
```

You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-date. `devtools::build_readme()` is handy for this. You could also use GitHub Actions to re-render `README.Rmd` every time you push. An example workflow can be found here: <https://github.com/r-lib/actions/tree/v1/examples>.

You can also embed plots, for example:

```{r pressure, echo = FALSE}
plot(pressure)
```

In that case, don't forget to commit and push the resulting figure files, so they display on GitHub and CRAN.

# use_readme_rmd() has expected form for a GitHub package

Code
writeLines(read_utf8("README.Rmd"))
Output
---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# {TESTPKG}

<!-- badges: start -->
<!-- badges: end -->

The goal of {TESTPKG} is to ...

## Installation

You can install the development version of {TESTPKG} from [GitHub](https://github.com/) with:

``` r
# install.packages("devtools")
devtools::install_github("OWNER/TESTPKG")
```

## Example

This is a basic example which shows you how to solve a common problem:

```{r example}
library({TESTPKG})
## basic example code
```

What is special about using `README.Rmd` instead of just `README.md`? You can include R chunks like so:

```{r cars}
summary(cars)
```

You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-date. `devtools::build_readme()` is handy for this. You could also use GitHub Actions to re-render `README.Rmd` every time you push. An example workflow can be found here: <https://github.com/r-lib/actions/tree/v1/examples>.

You can also embed plots, for example:

```{r pressure, echo = FALSE}
plot(pressure)
```

In that case, don't forget to commit and push the resulting figure files, so they display on GitHub and CRAN.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
First release:

* [ ] `usethis::use_cran_comments()`
* [ ] Update (aspirational) install instructions in README
* [ ] Proofread `Title:` and `Description:`
* [ ] Check that all exported functions have `@return` and `@examples`
* [ ] Check that `Authors@R:` includes a copyright holder (role 'cph')
Expand All @@ -32,7 +33,6 @@
* [ ] `usethis::use_github_release()`
* [ ] `usethis::use_dev_version()`
* [ ] `usethis::use_news_md()`
* [ ] Update install instructions in README
* [ ] Finish blog post
* [ ] Tweet
* [ ] Add link to blog post in pkgdown news menu
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ create_local_thing <- function(dir = file_temp(pattern = pattern),
invisible(proj_get())
}

scrub_testpkg <- function(message) {
gsub("testpkg[a-zA-Z0-9]+", "{TESTPKG}", message, perl = TRUE)
}

toggle_rlang_interactive <- function() {
# TODO: consider setting options(rlang_backtrace_on_error = "reminder") when
# in non-interactive mode, to suppress full backtraces
Expand Down
42 changes: 42 additions & 0 deletions tests/testthat/test-readme.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,45 @@ test_that("use_readme_rmd() sets up git pre-commit hook if pkg uses git", {
use_readme_rmd(open = FALSE)
expect_proj_file(".git", "hooks", "pre-commit")
})

test_that("use_readme_md() has expected form for a non-GitHub package", {
skip_if_not_installed("rmarkdown")
local_interactive(FALSE)

create_local_package()
use_readme_md()
expect_snapshot(writeLines(read_utf8("README.md")), transform = scrub_testpkg)
})

test_that("use_readme_md() has expected form for a GitHub package", {
skip_if_not_installed("rmarkdown")
local_interactive(FALSE)

create_local_package()
with_mock(
target_repo_spec = function(...) "OWNER/TESTPKG",
use_readme_md()
)
expect_snapshot(writeLines(read_utf8("README.md")), transform = scrub_testpkg)
})

test_that("use_readme_rmd() has expected form for a non-GitHub package", {
skip_if_not_installed("rmarkdown")
local_interactive(FALSE)

create_local_package()
use_readme_rmd()
expect_snapshot(writeLines(read_utf8("README.Rmd")), transform = scrub_testpkg)
})

test_that("use_readme_rmd() has expected form for a GitHub package", {
skip_if_not_installed("rmarkdown")
local_interactive(FALSE)

create_local_package()
with_mock(
target_repo_spec = function(...) "OWNER/TESTPKG",
use_readme_rmd()
)
expect_snapshot(writeLines(read_utf8("README.Rmd")), transform = scrub_testpkg)
})