Skip to content

Commit

Permalink
Utilize usethis::proj_set() instead of usethis::local_project()
Browse files Browse the repository at this point in the history
Second time writing this commit message since it got lost the first time =( I'm
now writing this commit on a text editor window just to be safe.

I see that `usethis::local_project()` runs `usethis::proj_set()` twice: first
for the new `path`, then inside a `withr::defer()` call that restores the
original path. I don't fully understand `withr::defer()`, but it seems to be
triggered earlier that I would like it to. That's why I'm seeing on the
README, some examples, and the vignette after
r-lib/usethis#1108 (comment)
paths that are not the one I expected (the one equivalent to
`file.path(tempdir(), "biocthisexample")`).

One option would be to rely on `usethis::with_project()` to get a similar
behavior to what I had with `withr::with_dir()`, however like Jenny Bryan
point out, this makes the code confusing for a new user to understand. That's
why it seems to me that `usethis::proj_set()` is the better option to use
in the examples, README and vignette code.

I'm also now using a second example package name in the vignette to avoid
clashing with the examples. The code doesn't overwrite the files by default,
so if you run the code with the same example twice you don't get to see the
output messages the second time.
  • Loading branch information
lcolladotor committed May 10, 2020
1 parent e89f16d commit dc38780
Show file tree
Hide file tree
Showing 23 changed files with 64 additions and 54 deletions.
4 changes: 2 additions & 2 deletions R/bioc_style.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
#' ## Create the example package in a temporary location
#' usethis::create_package(pkgdir)
#'
#' ## Set a local project to work with for the examples
#' usethis::local_project(pkgdir)
#' ## Set the project to use for the examples
#' usethis::proj_set(pkgdir)

This comment has been minimized.

Copy link
@jennybc

jennybc May 11, 2020

In normal usage, this will take care of itself, usually. Because open = rlang::is_interactive() and will do something sensible, depending on whether user is in RStudio or not. So you may not want to feature this code in the main examples, suggesting that users will need to call proj_set() themselves. That should be quite rare.

This comment has been minimized.

Copy link
@lcolladotor

lcolladotor May 12, 2020

Author Owner

Thanks again for looking into the code Jenny!

I just pushed d3dcab0 that is one attempt to hide usethis::proj_set() from the end users and minimize any confusion, while keeping "live" examples. Otherwise, BiocCheck::BiocCheck() complains (through an ERROR) that >=80% of the example files don't have runnable examples. Otherwise, I would just keep the example function calls under \dontrun{} tags.

This comment has been minimized.

Copy link
@jennybc

jennybc May 12, 2020

Yeah, this is the tension between writing examples that pass, e.g. CRAN's checks, and writing examples that show realistic use. For workflow-oriented packages, it is almost impossible to do both.

This comment has been minimized.

Copy link
@lcolladotor

lcolladotor May 12, 2020

Author Owner

Aye, and you are a trailblazer in this field (and many other ones). Thanks again for showing me the way and thinking about end users =)

#'
#' ## Automatically style the example package
#' styler::style_pkg(pkgdir, transformers = biocthis::bioc_style())
Expand Down
4 changes: 2 additions & 2 deletions R/use_bioc_citation.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#' ## Create the example package in a temporary location
#' usethis::create_package(pkgdir)
#'
#' ## Set a local project to work with for the examples
#' usethis::local_project(pkgdir)
#' ## Set the project to use for the examples
#' usethis::proj_set(pkgdir)
#'
#' ## Create a template CITATION file that is Bioconductor-friendly
#' biocthis::use_bioc_citation()
Expand Down
4 changes: 2 additions & 2 deletions R/use_bioc_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
#' ## Create the example package in a temporary location
#' usethis::create_package(pkgdir)
#'
#' ## Set a local project to work with for the examples
#' usethis::local_project(pkgdir)
#' ## Set the project to use for the examples
#' usethis::proj_set(pkgdir)
#'
#' ## Setup up git
#' usethis::use_git()
Expand Down
4 changes: 2 additions & 2 deletions R/use_bioc_github_action.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
#' ## Create the example package in a temporary location
#' usethis::create_package(pkgdir)
#'
#' ## Set a local project to work with for the examples
#' usethis::local_project(pkgdir)
#' ## Set the project to use for the examples
#' usethis::proj_set(pkgdir)
#'
#' ## Create a GitHub Actions workflow that is Bioconductor-friendly
#' biocthis::use_bioc_github_action()
Expand Down
4 changes: 2 additions & 2 deletions R/use_bioc_issue_template.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#' ## Create the example package in a temporary location
#' usethis::create_package(pkgdir)
#'
#' ## Set a local project to work with for the examples
#' usethis::local_project(pkgdir)
#' ## Set the project to use for the examples
#' usethis::proj_set(pkgdir)
#'
#' ## Create a template GitHub issue file that is Bioconductor-friendly
#' biocthis::use_bioc_issue_template()
Expand Down
4 changes: 2 additions & 2 deletions R/use_bioc_news_md.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#' ## Create the example package in a temporary location
#' usethis::create_package(pkgdir)
#'
#' ## Set a local project to work with for the examples
#' usethis::local_project(pkgdir)
#' ## Set the project to use for the examples
#' usethis::proj_set(pkgdir)
#'
#' ## Create a template NEWS.md file that is Bioconductor-friendly
#' biocthis::use_bioc_news_md()
Expand Down
4 changes: 2 additions & 2 deletions R/use_bioc_pkg_templates.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
#' ## Create the example package in a temporary location
#' usethis::create_package(pkgdir)
#'
#' ## Set a local project to work with for the examples
#' usethis::local_project(pkgdir)
#' ## Set the project to use for the examples
#' usethis::proj_set(pkgdir)
#'
#' ## Create the biocthis templates
#' biocthis::use_bioc_pkg_templates()
Expand Down
4 changes: 2 additions & 2 deletions R/use_bioc_readme_rmd.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
#' ## Create the example package in a temporary location
#' usethis::create_package(pkgdir)
#'
#' ## Set a local project to work with for the examples
#' usethis::local_project(pkgdir)
#' ## Set the project to use for the examples
#' usethis::proj_set(pkgdir)
#'
#' ## Setup up git
#' usethis::use_git()
Expand Down
4 changes: 2 additions & 2 deletions R/use_bioc_support.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#' ## Create the example package in a temporary location
#' usethis::create_package(pkgdir)
#'
#' ## Set a local project to work with for the examples
#' usethis::local_project(pkgdir)
#' ## Set the project to use for the examples
#' usethis::proj_set(pkgdir)
#'
#' ## Create a template GitHub support file that is Bioconductor-friendly
#' biocthis::use_bioc_support()
Expand Down
4 changes: 2 additions & 2 deletions R/use_bioc_vignette.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#' ## Create the example package in a temporary location
#' usethis::create_package(pkgdir)
#'
#' ## Set a local project to work with for the examples
#' usethis::local_project(pkgdir)
#' ## Set the project to use for the examples
#' usethis::proj_set(pkgdir)
#'
#' ## Create a template vignette file that is Bioconductor-friendly
#' biocthis::use_bioc_vignette("biocthisexample", "Introduction to biocthisexample")
Expand Down
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ pkgdir <- file.path(tempdir(), "biocthisexample")
## Create the example package in a temporary location
usethis::create_package(pkgdir)
## Set a local project to work with for the examples
usethis::local_project(pkgdir)
## Set the project to use for the examples
usethis::proj_set(pkgdir)
## Create the bioc templates
biocthis::use_bioc_pkg_templates()
Expand Down
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ pkgdir <- file.path(tempdir(), "biocthisexample")

## Create the example package in a temporary location
usethis::create_package(pkgdir)
#> ✓ Creating '/var/folders/cx/n9s558kx6fb7jf5z_pgszgb80000gn/T/RtmpSxZy15/biocthisexample/'
#> ✓ Setting active project to '/private/var/folders/cx/n9s558kx6fb7jf5z_pgszgb80000gn/T/RtmpSxZy15/biocthisexample'
#> ✓ Creating '/var/folders/cx/n9s558kx6fb7jf5z_pgszgb80000gn/T/RtmpPXAtNQ/biocthisexample/'
#> ✓ Setting active project to '/private/var/folders/cx/n9s558kx6fb7jf5z_pgszgb80000gn/T/RtmpPXAtNQ/biocthisexample'
#> ✓ Creating 'R/'
#> ✓ Writing 'DESCRIPTION'
#> Package: biocthisexample
Expand All @@ -99,14 +99,18 @@ usethis::create_package(pkgdir)
#> ✓ Writing 'NAMESPACE'
#> ✓ Setting active project to '<no active project>'

## Set a local project to work with for the examples
usethis::local_project(pkgdir)
#> ✓ Setting active project to '/private/var/folders/cx/n9s558kx6fb7jf5z_pgszgb80000gn/T/RtmpSxZy15/biocthisexample'
#> ✓ Setting active project to '<no active project>'
## Set the project to use for the examples
usethis::proj_set(pkgdir)
#> ✓ Setting active project to '/private/var/folders/cx/n9s558kx6fb7jf5z_pgszgb80000gn/T/RtmpPXAtNQ/biocthisexample'

## Create the bioc templates
biocthis::use_bioc_pkg_templates()
#> ✓ Setting active project to '/Users/lcollado/Dropbox/Code/biocthis'
#> ✓ Creating 'dev/'
#> ✓ Adding '^dev$' to '.Rbuildignore'
#> ✓ Writing 'dev/01_create_pkg.R'
#> ✓ Writing 'dev/02_git_github_setup.R'
#> ✓ Writing 'dev/03_core_files.R'
#> ✓ Writing 'dev/04_update.R'
```

The template `dev` scripts include comments and steps you can follow for
Expand All @@ -120,12 +124,18 @@ subject](https://www.jimhester.com/talk/2020-rsc-github-actions/).
``` r
## Create a GitHub Actions workflow that is Bioconductor-friendly
biocthis::use_bioc_github_action()
#> ✓ Creating '.github/'
#> ✓ Adding '^\\.github$' to '.Rbuildignore'
#> ✓ Adding '*.html' to '.github/.gitignore'
#> ✓ Creating '.github/workflows/'
#> ✓ Writing '.github/workflows/check-bioc.yml'
```

``` r
## Alternatively, use the general GitHub Actions workflow maintained by
## r-lib/actions
usethis::use_github_action("check-standard")
#> ✓ Writing '.github/workflows/check-standard.yaml'

## Or use the biocthis GHA workflow without having to install biocthis
usethis::use_github_action(
Expand Down
4 changes: 2 additions & 2 deletions man/bioc_style.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/use_bioc_citation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/use_bioc_description.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/use_bioc_github_action.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/use_bioc_issue_template.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/use_bioc_news_md.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/use_bioc_pkg_templates.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/use_bioc_readme_rmd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/use_bioc_support.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/use_bioc_vignette.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions vignettes/biocthis.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ library("styler")

If you haven't made an R package yet, you can do so using `r CRANpkg("usethis")`. That is, utilize `usethis::create_package()` with the package name of your choice. If you are using [RStudio Desktop](https://www.rstudio.com/products/rstudio/download) this function will open a new RStudio window and open R in the correct location. Otherwise, you might need to use `setwd()` to change directories.

In this vignette we will create an example package called `biocthisexample` on a temporary directory and work in this directory using `usethis::local_project()` in order to illustrate how the functions work. In a real world scenario, you would not use `usethis::local_project()` yourself and instead you would be working inside your R package.
In this vignette we will create an example package called `biocthispkg` on a temporary directory and work in this directory using `usethis::local_project()` in order to illustrate how the functions work. In a real world scenario, you would not use `usethis::local_project()` yourself and instead you would be working inside your R package.


```{r 'create_example_pkg'}
## Set the package name on a temporary directory
pkgdir <- file.path(tempdir(), "biocthisexample")
pkgdir <- file.path(tempdir(), "biocthispkg")
## Create the example package in a temporary location
usethis::create_package(pkgdir)
## Set a local project to work with for the examples
usethis::local_project(pkgdir)
## Set the project to use for the examples
usethis::proj_set(pkgdir)
```

Once you have created a package, you can use `use_bioc_pkg_templates()` to create a set of scripts in the `dev` (developer) directory.
Expand Down Expand Up @@ -282,7 +282,7 @@ biocthis::use_bioc_support()

```{r 'bioc_vignette'}
## Create a template vignette file that is Bioconductor-friendly
biocthis::use_bioc_vignette("biocthisexample", "Introduction to biocthisexample")
biocthis::use_bioc_vignette("biocthispkg", "Introduction to biocthispkg")
```

# Acknowledgments
Expand Down

0 comments on commit dc38780

Please sign in to comment.