Skip to content

Commit b093d9c

Browse files
committed
Merge branch 'talk-changes'
# Conflicts: # NEWS.md
2 parents 7d46424 + c81c4a9 commit b093d9c

File tree

6 files changed

+45
-5
lines changed

6 files changed

+45
-5
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: usethis
22
Title: Automate Package and Project Setup
3-
Version: 1.0.0
3+
Version: 1.0.0.9000
44
Authors@R: c(
55
person("Hadley", "Wickham", , "[email protected]", role = c("aut", "cre")),
66
person("RStudio", role = "cph")

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export(use_news_md)
3838
export(use_package)
3939
export(use_package_doc)
4040
export(use_pipe)
41+
export(use_r)
4142
export(use_rcpp)
4243
export(use_readme_md)
4344
export(use_readme_rmd)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# usethis 1.0.0.9000
22

3+
* `use_r()` creates and opens an `.R` file
4+
35
# usethis 1.0.0
46

57
This is a new package that extracts out many functions that previously lived in devtools, as well as providing more building blocks so you can create your own helpers. As well as the many new helpers listed below, there are three main improvements to the package:

R/edit.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ edit_git_config <- function(scope = c("user", "project")) {
5454
#' @rdname edit
5555
edit_git_ignore <- function(scope = c("user", "project")) {
5656
scope <- match.arg(scope)
57-
switch(scope,
58-
user = edit_file("~", ".gitignore"),
59-
project = edit_file(proj_get(), ".git/ignore")
60-
)
57+
edit_file(scope_dir(scope), ".gitignore")
6158
invisible()
6259
}
6360

R/r.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#' Create a new R file.
2+
#'
3+
#' @param name File name, without extension.
4+
#' @export
5+
use_r <- function(name) {
6+
check_file_name(name)
7+
8+
use_directory("R")
9+
edit_file(proj_get(), paste0("R/", name, ".R"))
10+
11+
invisible(TRUE)
12+
}
13+
14+
check_file_name <- function(name) {
15+
if (!valid_file_name(name)) {
16+
stop(
17+
value(name), " is not a valid file name. It should:\n",
18+
"* Contain only ASCII letters, numbers, '-', and '_'\n",
19+
call. = FALSE
20+
)
21+
}
22+
}
23+
24+
valid_file_name <- function(x) {
25+
grepl("^[[:alpha:]_-]+$", x)
26+
}

man/use_r.Rd

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)