Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dreamRs/prefixer
Prefix function with their namespace & other development tools
https://github.com/dreamRs/prefixer
addin r r-package rstudio-addin
Last synced: 3 months ago
JSON representation
Prefix function with their namespace & other development tools
- Host: GitHub
- URL: https://github.com/dreamRs/prefixer
- Owner: dreamRs
- License: gpl-3.0
- Created: 2018-01-06T08:57:24.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-09-09T15:55:40.000Z (over 3 years ago)
- Last Synced: 2024-08-13T07:15:42.046Z (6 months ago)
- Topics: addin, r, r-package, rstudio-addin
- Language: R
- Homepage:
- Size: 199 KB
- Stars: 141
- Watchers: 8
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- jimsghstars - dreamRs/prefixer - Prefix function with their namespace & other development tools (R)
README
# prefixer::
> Prefix function with their namespace and other tools for writing functions / packages
[](https://travis-ci.org/dreamRs/prefixer)
[](http://www.repostatus.org/#active)
[](https://www.tidyverse.org/lifecycle/#stable)
[](https://github.com/dreamRs/prefixer/actions)## Overview
It can be useful to prefix function in a script to prevent use of the wrong one, e.g. `stats::filter` vs `dplyr::filter` or `plyr::summarise` vs `dplyr::summarise`.
This package provide a Shiny gadget to interactively add prefix to function in a script, if a function exist in several packages, you can choose the one you want use.If you're in a package, you can generate `@importFrom` tag from function definition and after remove prefix if needed.
Installation :
```r
# with remotes
remotes::install_github("dreamRs/prefixer")
```:warning: functions of this package will modify your scripts
## prefixer:: gadget
You can launch the addin via RStudio's Addins menu. Interface looks like this :

```r
fread_dir <- function(path, pattern = "\\.csv$") {
paths <- list.files(path = path, pattern = pattern, full.names = TRUE)
files <- lapply(paths, fread)
files <- setNames(files, paths)
rbindlist(l = files, idcol = "path")
}
```Becomes =>
```r
fread_dir <- function(path, pattern = "\\.csv$") {
paths <- list.files(path = path, pattern = pattern, full.names = TRUE)
files <- lapply(paths, data.table::fread)
files <- stats::setNames(files, paths)
data.table::rbindlist(l = files, idcol = "path")
}
```## @importFrom
From prefixed functions, you can generate roxygen `@importFrom` tag via addin *@importFrom*.
Or manually with `import_from(fun = fread_dir)`:
```r
#' @importFrom data.table fread rbindlist
#' @importFrom stats setNames
fread_dir <- function(path, pattern = "\\.csv$") {
paths <- list.files(path = path, pattern = pattern, full.names = TRUE)
files <- lapply(paths, data.table::fread)
files <- stats::setNames(files, paths)
data.table::rbindlist(l = files, idcol = "path")
}
```## Unprefix
After generated `@importFrom` tags, you can if you want remove prefix before your functions via addin *Unprefix* :
```r
#' @importFrom data.table fread rbindlist
#' @importFrom stats setNames
fread_dir <- function(path, pattern = "\\.csv$") {
paths <- list.files(path = path, pattern = pattern, full.names = TRUE)
files <- lapply(paths, fread)
files <- setNames(files, paths)
rbindlist(l = files, idcol = "path")
}
```## Roxygen comments
Addin *Roxygen comment* allow to comment selected line with `#'`.
## Not-ASCII
Addin *Not-ASCII* escape all not-ASCII characters between quotes to Unicode, to avoid warning in R CMD check :
```r
frenchFileInput <- function(inputId) {
fileInput(
inputId = inputId,
label = "Sélectionner un fichier :",
buttonLabel = "Parcourir...",
placeholder = "Aucun fichier sélectionné"
)
}
```
becomes =>```r
frenchFileInput <- function(inputId) {
fileInput(
inputId = inputId,
label = "S\u00e9lectionner un fichier :",
buttonLabel = "Parcourir...",
placeholder = "Aucun fichier s\u00e9lectionn\u00e9"
)
}
```## Show Non-ASCII files
Show files containing Non-ASCII characters in RStudio markers tabs. This function is similar to `tools::showNonASCIIfile`.
```r
show_nonascii_file()
```
## Check Rd files
Check if your Rd files (documentation) contains examples and return value:
```r
check_Rd_examples()
# 1 Rd file(s) with no examples.
# - unprefix.Rdcheck_Rd_value()
# 2 Rd file(s) with no value.
# - prefixer.Rd
# - unprefix.Rd
```## Count calls
Get functions used in scripts and where they come from, for example functions used in this package:
```r
count_calls("R/")
# call n package
# 1 tags 36 htmltools
# 2 rstudioapi 15
# 3 str_replace_all 15 stringr
# 4 div 9 htmltools
# 5 b 8
# 6 observeEvent 8 shiny
# 7 pre 6 htmltools
# 8 set_selection 6 prefixer
# 9 getSourceEditorContext 5 rstudioapi
# 10 insertText 5 rstudioapi
# ...
```