Skip to content

Commit

Permalink
Merge pull request #46 from bcgov/devel
Browse files Browse the repository at this point in the history
v1.0.1 - Fix bugs from internal usethis changes (and others)
  • Loading branch information
boshek authored Aug 17, 2018
2 parents 27d17b0 + c499c70 commit 7c0bce5
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 61 deletions.
1 change: 0 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
^README\.Rmd$
^Install_Instructions\.md$
CODE_OF_CONDUCT.md
^img/
10 changes: 6 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: bcgovr
Title: Set up of bcgov R projects & packages
Version: 1.0
Title: Set Up of 'bcgov' R Projects & Packages
Version: 1.0.1
Authors@R: c(person("Andy", "Teucher", role = c("aut", "cre"), email =
"andy.teucher@gov.bc.ca"),
person("Stephanie", "Hazlitt", role = "aut",
Expand All @@ -25,7 +25,9 @@ Imports:
usethis (>= 1.1.0)
Suggests:
testthat,
roxygen2
roxygen2,
rmarkdown
LazyData: true
RoxygenNote: 6.0.1
RoxygenNote: 6.1.0
Roxygen: list(markdown = TRUE)
Encoding: UTF-8
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# bcgovr 1.0.1

* Fixed bugs due to changes in `usethis` internal functions (#45, #46)

# bcgovr 1.0
### 🎉 NO FUNCTION LEFT STANDING 🎉
* Redesigned under-the-hood of `bcgovr`, all functions now wrap a subset of [`usethis`](https://cran.r-project.org/web/packages/usethis/index.html) 📦 functions with the addition of bcgov-specific defaults & requirements
* Redesigned under-the-hood of `bcgovr`, all functions now wrap a subset of [`usethis`](https://cran.r-project.org/package=usethis) 📦 functions with the addition of bcgov-specific defaults & requirements
* Renamed **all** `bcgovr` functions, functions now start with verbs with easier look-up & auto-complete when using RStudio
* Added an RStudio Addin for inserting the boiler-plate Creative Commons Attribution 4.0 International License header

Expand Down
15 changes: 7 additions & 8 deletions R/create.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ create_bcgov_project <- function(path = ".", rmarkdown = TRUE,
}

## Add the necessary R files and directories
usethis:::done("Creating new project")
usethis:::done("Populating with directory structure")
done("Creating new project")
done("Populating with directory structure")
lapply(c(dirs, filedirs), dir.create, recursive = TRUE, showWarnings = FALSE)
lapply(files, file.create)
# Insert appropriate licence header into source files
Expand Down Expand Up @@ -133,8 +133,8 @@ create_bcgov_package <- function(path = ".", rmarkdown = TRUE,
)

## Add in package setup files
usethis::create_package(path = path, fields = bcgovr_desc, rstudio = rstudio,
open = FALSE)
usethis::create_package(path = normalizePath(path), fields = bcgovr_desc,
rstudio = rstudio, open = FALSE)

## Add individual elements via usethis
usethis::use_news_md(open = FALSE)
Expand Down Expand Up @@ -198,7 +198,7 @@ create_from_bcgov_github <- function(repo,

is_git_installed()
repo_clone_cmd <- paste0("git clone -q https://github.com/",repo, " ", local_repo_path)
usethis:::done("Using system call to git")
done("Using system call to git")
system(repo_clone_cmd)
usethis::proj_set(local_repo_path, force = TRUE)
} else {
Expand All @@ -214,17 +214,16 @@ create_from_bcgov_github <- function(repo,
#' Get the path to the current project if it exists, otherwise return NULL
#' @noRd
get_proj <- function() {
if (usethis:::is_package() | usethis:::is_proj()) {
if (usethis:::is_package() || usethis:::possibly_in_proj(".")) {
return(usethis::proj_get())
}
NULL
}

#' Create a project if one doesn't exist
#' @noRd

create_proj <- function(path = ".", rstudio) {
if (!(usethis:::is_package(path) | usethis:::is_proj(path))) {
if (!(usethis:::is_package(path) || usethis:::possibly_in_proj(path))) {
usethis::create_project(path = path, open = FALSE, rstudio = rstudio)
} else {
usethis::proj_set(path, force = TRUE)
Expand Down
6 changes: 4 additions & 2 deletions R/licence_header.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ insert_bcgov_apache_header <- function(file, year = format(Sys.Date(), "%Y")) {
licence_text <- make_licence_header_text(year, "apache")

write_licence_header(licence_text, file)
usethis:::done("Adding Apache boilerplate header to the top of ", usethis:::value(file))
done("Adding Apache boilerplate header to the top of ",
colour_string(file))

invisible(TRUE)
}
Expand All @@ -39,7 +40,8 @@ insert_bcgov_cc_header <- function(file, year = format(Sys.Date(), "%Y")) {
licence_text <- make_licence_header_text(year, "cc-by")

write_licence_header(licence_text, file)
usethis:::done("Adding CC-BY 4.0 boilerplate header to the top of ", usethis:::value(file))
done("Adding CC-BY 4.0 boilerplate header to the top of ",
colour_string(file))

invisible(TRUE)
}
Expand Down
18 changes: 11 additions & 7 deletions R/r_setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ set_home <- function() {
# Get existing HOME
home_dir <- Sys.getenv("HOME")
if (win_env_is_good("HOME")) {
usethis:::done("HOME env variable already set appropriately")
done("HOME env variable already set appropriately")
return(invisible(home_dir))
}

Expand All @@ -62,17 +62,18 @@ set_home <- function() {
# Check and make sure it worked
home_dir <- Sys.getenv("HOME")
if (result > 0L || home_dir != user_profile_dir) stop("HOME not set")
usethis:::done("HOME env variable set to ", usethis:::value(home_dir))
done("HOME env variable set to ",
colour_string(home_dir))

# Copy any existing .Renviron or .Rprofile files over to new HOME
if (file.exists(renviron_file)) {
file.copy(renviron_file, home_dir)
usethis:::done("Copied existing .Renviron to new HOME directory")
done("Copied existing .Renviron to new HOME directory")
}

if (file.exists(rprofile_file)) {
file.copy(rprofile_file, home_dir)
usethis:::done("Copied existing .Rprofile to new HOME directory")
done("Copied existing .Rprofile to new HOME directory")
}

# If there isn't a library set already, set .libPaths in
Expand Down Expand Up @@ -120,7 +121,8 @@ set_cran_repo <- function() {
# Set CRAN repo in current session too so user doesn't have to restart
eval(parse(text = set_repo_text))

usethis:::done("Setting default CRAN repository to \"https://cran.rstudio.com\" in ", usethis:::value(rprofile_file))
done("Setting default CRAN repository to \"https://cran.rstudio.com\" in ",
colour_string(rprofile_file))
invisible(TRUE)
}

Expand All @@ -134,7 +136,8 @@ win_env_is_good <- function(env_var = "HOME") {
set_session_lib_path <- function() {
path <- make_new_libpath()
.libPaths(new = path)
usethis:::done("Setting library location to ", usethis:::value(path))
done("Setting library location to ",
colour_string(path))
}

#' @noRd
Expand All @@ -143,7 +146,8 @@ copy_packages <- function() {
oldpath <- gsub("/bcgovr$", "", find.package("bcgovr"))
newpath <- make_new_libpath()
packages <- list.dirs(oldpath, full.names = TRUE, recursive = FALSE)
usethis:::done("Copying installed packages to new library location at ", usethis:::value(newpath))
done("Copying installed packages to new library location at ",
colour_string(newpath))
file.copy(packages, newpath, recursive = TRUE)
}

Expand Down
15 changes: 13 additions & 2 deletions R/style.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.

done <- function(...) {
cat(paste0(crayon::green(clisymbols::symbol$tick), " ", ...),
"\n", sep = "")
}

not_done <- function(...) {
usethis:::bullet(paste0(...), bullet = crayon::red(clisymbols::symbol$cross))
cat(paste0(crayon::red(clisymbols::symbol$cross), " ", ...),
"\n", sep = "")
}

congrats <- function(...) {
usethis:::bullet(paste0(...), bullet = crayon::yellow(clisymbols::symbol$star))
cat(paste0(crayon::yellow(clisymbols::symbol$star), " ", ...),
"\n", sep = "")
}

colour_string <- function(...) {
crayon::blue(encodeString(paste0(...), quote = "'"))
}
16 changes: 3 additions & 13 deletions R/use.R
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ use_bcgov_github <- function(organisation = "bcgov", rmarkdown = TRUE,
if (grepl("(unable to find an inherited method)|(error authenticating)", e$message)) {
is_git_installed()
repo_clone_cmd <- paste0("git push -u origin master")
usethis:::done("Using system call to git")
done("Using system call to git")
system(repo_clone_cmd)
usethis:::done("Navigate to https://github.com/",organisation, "/", basename(usethis::proj_get()), " to view your repo")
done("Navigate to https://github.com/",organisation, "/", basename(usethis::proj_get()), " to view your repo")
} else {
stop(e)
}
Expand Down Expand Up @@ -261,16 +261,6 @@ coc_email argument. See ?use_bcgov_code_of_conduct", call. = FALSE))

use_bcgov_template <- function(template, save_as = template, data = list(),
ignore = FALSE, open = FALSE) {
tryCatch(
usethis::use_template(template = template, save_as = save_as, data = data,
ignore = ignore, open = open, package = "bcgovr"),
error = function(e) {
if (grepl("already exists", e$message)) {
not_done(e$message)
}
else {
stop(e)
}
}
)
ignore = ignore, open = open, package = "bcgovr")
}
18 changes: 9 additions & 9 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ output:
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "img/README-"
fig.path = "tools/readme/"
)
```

# bcgovr <img src="img/logo.png" align="right" />
# bcgovr <img src="tools/readme/logo.png" align="right" />

<a rel="Delivery" href="https://github.com/BCDevExchange/assets/blob/master/README.md"><img alt="In production, but maybe in Alpha or Beta. Intended to persist and be supported." style="border-width:0" src="https://assets.bcdevexchange.org/images/badges/delivery.svg" title="In production, but maybe in Alpha or Beta. Intended to persist and be supported." /></a>[![Travis-CI Build Status](https://travis-ci.org/bcgov/bcgovr.svg?branch=master)](https://travis-ci.org/bcgov/bcgovr)[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

Expand Down Expand Up @@ -59,7 +59,7 @@ The `bcgovr` package installs a set of [RStudio Addins](https://rstudio.github.i

## Installation

You can install `bcgovr` directly from this GitHub repository. To do so, you will need the [remotes](https://cran.r-project.org/web/packages/remotes/index.html) package:
You can install `bcgovr` directly from this GitHub repository. To do so, you will need the [remotes](https://cran.r-project.org/package=remotes) package:

```{r, eval=FALSE}
install.packages("remotes")
Expand All @@ -72,7 +72,7 @@ remotes::install_github("bcgov/bcgovr")
library(bcgovr)
```

`r emo::ji("tada")` The authors of `bcgovr` acknowledge and thank the authors of the [`usethis`](https://cran.r-project.org/web/packages/usethis/index.html) R package&mdash;`bcgovr` uses `usethis` _a lot_. And by a lot, we mean _every_ `bcgovr` function uses `usethis` under the hood `r emo::ji("oncoming_automobile")`.
`r emo::ji("tada")` The authors of `bcgovr` acknowledge and thank the authors of the [`usethis`](https://cran.r-project.org/package=usethis) R package&mdash;`bcgovr` uses `usethis` _a lot_. And by a lot, we mean _every_ `bcgovr` function uses `usethis` under the hood `r emo::ji("oncoming_automobile")`.


## Usage
Expand Down Expand Up @@ -132,9 +132,9 @@ C:/mynewrpackage
Users can also use the *bcgovr Project & Package* templates in the [RStudio](https://www.rstudio.com/) New Project dialogue box to create a new R project or package. The dialogue box provides the option to select and individualise the required bcgov GitHub files and initialise Git version control.

```{r echo=FALSE, out.width = "30%"}
knitr::include_graphics("img/proj_template1.png")
knitr::include_graphics("img/proj_template2.png")
knitr::include_graphics("img/proj_template3.png")
knitr::include_graphics("tools/readme/proj_template1.png")
knitr::include_graphics("tools/readme/proj_template2.png")
knitr::include_graphics("tools/readme/proj_template3.png")
```

<br />
Expand Down Expand Up @@ -224,7 +224,7 @@ use_bcgov_code_of_conduct(coc_email = "my.email@gov.bc.ca")

Need to add that Apache 2.0 or Creative Commons License header to a source file? Just click-click:

![](img/bcgovr_addin_licence.gif)
![](tools/readme/bcgovr_addin_licence.gif)

You can also use `insert_bcgov_apache_header()` or `insert_bcgov_cc_header()`.

Expand All @@ -240,7 +240,7 @@ You can also use `insert_bcgov_apache_header()` or `insert_bcgov_cc_header()`.

Need to add a Project State Badge to your README file? Just click-click-click-click:

![](img/bcgovr_addin_badge.gif)
![](tools/readme/bcgovr_addin_badge.gif)

You can also use `insert_bcgov_devex_badge("inspiration")`. Type `?insert_bcgov_devex_badge` in the R console for the list of badge options and other help.

Expand Down
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<!-- README.md is generated from README.Rmd. Please edit README.Rmd (this file) -->

# bcgovr <img src="img/logo.png" align="right" />
# bcgovr <img src="tools/readme/logo.png" align="right" />

<a rel="Delivery" href="https://github.com/BCDevExchange/assets/blob/master/README.md"><img alt="In production, but maybe in Alpha or Beta. Intended to persist and be supported." style="border-width:0" src="https://assets.bcdevexchange.org/images/badges/delivery.svg" title="In production, but maybe in Alpha or Beta. Intended to persist and be supported." /></a>[![Travis-CI
Build
Expand Down Expand Up @@ -90,8 +90,7 @@ Addins](https://rstudio.github.io/rstudioaddins/):
## Installation

You can install `bcgovr` directly from this GitHub repository. To do so,
you will need the
[remotes](https://cran.r-project.org/web/packages/remotes/index.html)
you will need the [remotes](https://cran.r-project.org/package=remotes)
package:

``` r
Expand All @@ -107,8 +106,8 @@ library(bcgovr)
```

🎉 The authors of `bcgovr` acknowledge and thank the authors of the
[`usethis`](https://cran.r-project.org/web/packages/usethis/index.html)
R package—`bcgovr` uses `usethis` *a lot*. And by a lot, we mean *every*
[`usethis`](https://cran.r-project.org/package=usethis) R
package—`bcgovr` uses `usethis` *a lot*. And by a lot, we mean *every*
`bcgovr` function uses `usethis` under the hood 🚘.

## Usage
Expand Down Expand Up @@ -183,7 +182,7 @@ and individualise the required bcgov GitHub files and initialise Git
version
control.

<img src="img/proj_template1.png" width="30%" /><img src="img/proj_template2.png" width="30%" /><img src="img/proj_template3.png" width="30%" />
<img src="tools/readme/proj_template1.png" width="30%" /><img src="tools/readme/proj_template2.png" width="30%" /><img src="tools/readme/proj_template3.png" width="30%" />

<br />

Expand Down Expand Up @@ -304,7 +303,7 @@ file</strong></summary>
Need to add that Apache 2.0 or Creative Commons License header to a
source file? Just click-click:

![](img/bcgovr_addin_licence.gif)
![](tools/readme/bcgovr_addin_licence.gif)

You can also use `insert_bcgov_apache_header()` or
`insert_bcgov_cc_header()`.
Expand All @@ -323,7 +322,7 @@ README file</strong></summary>
Need to add a Project State Badge to your README file? Just
click-click-click-click:

![](img/bcgovr_addin_badge.gif)
![](tools/readme/bcgovr_addin_badge.gif)

You can also use `insert_bcgov_devex_badge("inspiration")`. Type
`?insert_bcgov_devex_badge` in the R console for the list of badge
Expand Down
7 changes: 4 additions & 3 deletions man/create_bcgov_project.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_bcgov_github.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/helper.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (!usethis:::is_proj()) {
if (!usethis:::possibly_in_proj()) {
file.create(".here")
tmp_here <- TRUE
} else {
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes

0 comments on commit 7c0bce5

Please sign in to comment.