Skip to content

Commit 79e63a3

Browse files
committed
Initial working version
1 parent f4f0dda commit 79e63a3

22 files changed

+430
-33
lines changed

.Rbuildignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
^.*\.Rproj$
2+
^\.Rproj\.user$
3+
^README\.Rmd$
4+
^\.github$
5+
^LICENSE\.md$

.github/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.html

.github/workflows/R-CMD-check.yaml

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
2+
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
branches:
10+
- main
11+
- master
12+
13+
name: R-CMD-check
14+
15+
jobs:
16+
R-CMD-check:
17+
runs-on: ${{ matrix.config.os }}
18+
19+
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
20+
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
config:
25+
- {os: windows-latest, r: 'release'}
26+
- {os: macOS-latest, r: 'release'}
27+
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
28+
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
29+
30+
env:
31+
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
32+
RSPM: ${{ matrix.config.rspm }}
33+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
34+
35+
steps:
36+
- uses: actions/checkout@v2
37+
38+
- uses: r-lib/actions/setup-r@v1
39+
with:
40+
r-version: ${{ matrix.config.r }}
41+
42+
- uses: r-lib/actions/setup-pandoc@v1
43+
44+
- name: Query dependencies
45+
run: |
46+
install.packages('remotes')
47+
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
48+
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
49+
shell: Rscript {0}
50+
51+
- name: Cache R packages
52+
if: runner.os != 'Windows'
53+
uses: actions/cache@v2
54+
with:
55+
path: ${{ env.R_LIBS_USER }}
56+
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
57+
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
58+
59+
- name: Install system dependencies
60+
if: runner.os == 'Linux'
61+
run: |
62+
while read -r cmd
63+
do
64+
eval sudo $cmd
65+
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
66+
67+
- name: Install dependencies
68+
run: |
69+
remotes::install_deps(dependencies = TRUE)
70+
remotes::install_cran("rcmdcheck")
71+
shell: Rscript {0}
72+
73+
- name: Check
74+
env:
75+
_R_CHECK_CRAN_INCOMING_REMOTE_: false
76+
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
77+
shell: Rscript {0}
78+
79+
- name: Upload check results
80+
if: failure()
81+
uses: actions/upload-artifact@main
82+
with:
83+
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
84+
path: check

.github/workflows/pkgdown.yaml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
- master
6+
7+
name: pkgdown
8+
9+
jobs:
10+
pkgdown:
11+
runs-on: macOS-latest
12+
env:
13+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- uses: r-lib/actions/setup-r@v1
18+
19+
- uses: r-lib/actions/setup-pandoc@v1
20+
21+
- name: Query dependencies
22+
run: |
23+
install.packages('remotes')
24+
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
25+
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
26+
shell: Rscript {0}
27+
28+
- name: Cache R packages
29+
uses: actions/cache@v2
30+
with:
31+
path: ${{ env.R_LIBS_USER }}
32+
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
33+
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
34+
35+
- name: Install dependencies
36+
run: |
37+
remotes::install_deps(dependencies = TRUE)
38+
install.packages("pkgdown", type = "binary")
39+
shell: Rscript {0}
40+
41+
- name: Install package
42+
run: R CMD INSTALL .
43+
44+
- name: Deploy package
45+
run: |
46+
git config --local user.email "[email protected]"
47+
git config --local user.name "GitHub Actions"
48+
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)'

.github/workflows/test-coverage.yaml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
- master
6+
pull_request:
7+
branches:
8+
- main
9+
- master
10+
11+
name: test-coverage
12+
13+
jobs:
14+
test-coverage:
15+
runs-on: macOS-latest
16+
env:
17+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
18+
steps:
19+
- uses: actions/checkout@v2
20+
21+
- uses: r-lib/actions/setup-r@v1
22+
23+
- uses: r-lib/actions/setup-pandoc@v1
24+
25+
- name: Query dependencies
26+
run: |
27+
install.packages('remotes')
28+
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
29+
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
30+
shell: Rscript {0}
31+
32+
- name: Cache R packages
33+
uses: actions/cache@v2
34+
with:
35+
path: ${{ env.R_LIBS_USER }}
36+
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
37+
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
38+
39+
- name: Install dependencies
40+
run: |
41+
install.packages(c("remotes"))
42+
remotes::install_deps(dependencies = TRUE)
43+
remotes::install_cran("covr")
44+
shell: Rscript {0}
45+
46+
- name: Test coverage
47+
run: covr::codecov()
48+
shell: Rscript {0}

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.Rproj.user
2+
.Rhistory
3+
.RData
4+
.Ruserdata

DESCRIPTION

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
Package: herehelper
22
Type: Package
33
Title: What the Package Does (Title Case)
4-
Version: 0.1.0
4+
Version: 0.1.0.900
55
Author: Who wrote it
66
Maintainer: The package maintainer <[email protected]>
77
Description: More about what it does (maybe more than one line)
88
Use four spaces when indenting paragraphs within the Description.
9-
License: What license is it under?
9+
License: MIT + file LICENSE
1010
Encoding: UTF-8
1111
LazyData: true
12+
RoxygenNote: 7.1.1
13+
Imports:
14+
rstudioapi (>= 0.11),
15+
stringr (>= 1.4)
16+
Suggests:
17+
testthat,
18+
spelling
19+
Language: en-US

LICENSE

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
YEAR: 2020
2+
COPYRIGHT HOLDER: Luke A McGuinness

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# MIT License
2+
3+
Copyright (c) 2020 Luke A McGuinness
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

NAMESPACE

+4-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
exportPattern("^[[:alpha:]]+")
1+
# Generated by roxygen2: do not edit by hand
2+
3+
export(get_info)
4+
export(here_clean_path)

R/hello.R

-18
This file was deleted.

R/replace_path.R

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#' Get information on the highlighted path from the editor
2+
#'
3+
#' @param context Context of the text
4+
#'
5+
#' @return Information about the highlighted text
6+
#' @export
7+
8+
get_info <- function(context) {
9+
10+
id <- context[["id"]]
11+
12+
path_text <- rstudioapi::primary_selection(context)[["text"]]
13+
14+
range <- rstudioapi::primary_selection(context)[["range"]]
15+
16+
info <- list(range = range, path_text = path_text, id = id)
17+
18+
return(info)
19+
}
20+
21+
22+
#' Correctly format path to match here::here() guidelines
23+
#'
24+
#' @return Updated path as recommended by here::here(), split into individual
25+
#' quoted and comma-separated segments.
26+
#' @export
27+
here_clean_path <- function() {
28+
29+
# Get information
30+
info <- get_info(context = rstudioapi::getSourceEditorContext())
31+
32+
# Get code
33+
path_text <- split_path(info[["path_text"]])
34+
35+
# Update highlighted code
36+
rstudioapi::modifyRange(info[["range"]], path_text, info[["id"]])
37+
}
38+
39+
#' Split path by slashes and quote and comma-separate result.
40+
#'
41+
#' @param text File path to reformat
42+
#'
43+
#' @return
44+
#' @export
45+
split_path <- function(text){
46+
47+
# Replace forward-slash
48+
text <- stringr::str_replace_all(text,"/","\",\"")
49+
50+
# Replace back-slash
51+
text <- stringr::str_replace_all(text,"\\\\","\",\"")
52+
53+
return(text)
54+
}

README.Rmd

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
output: github_document
3+
---
4+
5+
<!-- README.md is generated from README.Rmd. Please edit that file -->
6+
7+
```{r, include = FALSE}
8+
knitr::opts_chunk$set(
9+
collapse = TRUE,
10+
comment = "#>",
11+
fig.path = "man/figures/README-",
12+
out.width = "100%"
13+
)
14+
```
15+
16+
# herehelper
17+
18+
<!-- badges: start -->
19+
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
20+
[![R build status](https://github.com/mcguinlu/herehelper/workflows/R-CMD-check/badge.svg)](https://github.com/mcguinlu/herehelper/actions)
21+
<!-- badges: end -->
22+
23+
The purpose of `herehelper` is singular and simple - to allow you to use the RStudio file path auto-complete functionality and then quickly reformat your code to match here::here() guidelines.
24+
25+
``` {r, eval = FALSE}
26+
here::here("data/2020/06/01/data.csv")
27+
28+
# becomes
29+
30+
here::here("data","2020","06","01","data.csv")
31+
```
32+
33+
This functionality is designed to work via an RStudio addin - simply highlight your file path, browse to the `herehelper` section in the RStudio Addins drop-down menu, and select "Format path for use with here::here()".
34+
35+
Alternatively you can [bind the functionality to a keyboard shortcut](https://support.rstudio.com/hc/en-us/articles/206382178-Customizing-Keyboard-Shortcuts) - I personally like mapping it to `CRTL+/`.
36+
37+
## Installation
38+
39+
You can install the development version from [GitHub](https://github.com/) with:
40+
41+
``` {r, eval = FALSE}
42+
# install.packages("devtools")
43+
devtools::install_github("mcguinlu/herehelper")
44+
library(herehelper)
45+
```
46+
47+
## To Do
48+
49+
Make a video demonstrating the functionality.

0 commit comments

Comments
 (0)