Skip to content

Commit 5491eef

Browse files
committed
Implement first browse functions
Fixes #96
1 parent b093d9c commit 5491eef

File tree

5 files changed

+85
-1
lines changed

5 files changed

+85
-1
lines changed

NAMESPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
export(browse_cran)
4+
export(browse_github)
5+
export(browse_github_issues)
6+
export(browse_github_pulls)
37
export(create_package)
48
export(create_project)
59
export(edit_git_config)

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+
* New family of `browse_` functions that open useful websites (#96)
4+
35
* `use_r()` creates and opens an `.R` file
46

57
# usethis 1.0.0

R/browse.R

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#' Quickly browse to important package webpages
2+
#'
3+
#' @param package Name of package; leave as `NULL` to use current package
4+
#' @export
5+
#' @examples
6+
#' browse_cran("MASS")
7+
browse_github <- function(package = NULL) {
8+
view_url(github_home(package = package))
9+
}
10+
11+
#' @export
12+
#' @rdname browse_github
13+
browse_github_issues <- function(package = NULL) {
14+
view_url(github_home(package = package), "/issues")
15+
}
16+
17+
#' @export
18+
#' @rdname browse_github
19+
browse_github_pulls <- function(package = NULL) {
20+
view_url(github_home(package = package), "/pulls")
21+
}
22+
23+
#' @export
24+
#' @rdname browse_github
25+
browse_cran <- function(package = NULL) {
26+
view_url(cran_home(package = package))
27+
}
28+
29+
github_home <- function(package = NULL) {
30+
if (is.null(package)) {
31+
desc <- desc::desc(proj_get())
32+
} else {
33+
desc <- desc::desc(package = package)
34+
}
35+
36+
urls <- desc$get_urls()
37+
gh_links <- grep("^https?://github.com/", urls, value = TRUE)
38+
39+
if (length(gh_links) == 0) {
40+
stop("Couldn't find GitHub home", call. = FALSE)
41+
}
42+
43+
gh_links[[1]]
44+
}
45+
46+
47+
cran_home <- function(package = NULL) {
48+
package <- package %||% project_name()
49+
50+
paste0("https://cran.r-project.org/package=", package)
51+
}

R/helpers.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ edit_file <- function(base_path, path) {
184184
invisible()
185185
}
186186

187-
view_url <- function(url, open = interactive()) {
187+
view_url <- function(..., open = interactive()) {
188+
url <- paste0(...)
188189
if (open) {
189190
done("Opening url")
190191
utils::browseURL(url)

man/browse_github.Rd

Lines changed: 26 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)