GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - mcguinlu/pathformatr: Auto-complete your file path natively in RStudio, then use the {pathformatr} add-in to quickly reformat your path for use with here::here() or file.path()

BranchesTags
Open more actions menu

Latest commit

 

History

20 Commits
20 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
R
R
 
 
inst
inst
 
 
man
man
 
 
tests
tests
 
 
.Rbuildignore
.Rbuildignore
 
 
.gitignore
.gitignore
 
 
DESCRIPTION
DESCRIPTION
 
 
LICENSE
LICENSE
 
 
LICENSE.md
LICENSE.md
 
 
NAMESPACE
NAMESPACE
 
 
NEWS.md
NEWS.md
 
 
README.Rmd
README.Rmd
 
 
README.md
README.md
 
 
demo.gif
demo.gif
 
 
pathformatr.Rproj
pathformatr.Rproj
 
 

Repository files navigation

pathformatr

Lifecycle: stable R build status

Installation

devtools::install_github("mcguinlu/pathformatr")
library(pathformatr)

Functionality

The purpose of pathformatr is singular and simple - to allow you to use the RStudio file path auto-complete functionality in here() and file.path() calls and then quickly reformat the resulting file path to use quoted, comma-separated elements:

here::here("data/2020/06/01/data.csv")
# or
here::here("data\2020\06\01\data.csv")

# becomes

here::here("data", "2020", "06", "01", "data.csv")

This functionality is available via the format_path() function, but is designed to work best via an RStudio AddIn - simply highlight your entire function call (i.e. “here(” to “)” inclusive)[1], browse to the pathformatr section in the RStudio Addins drop-down menu, and select “Split file path into quoted and comma-separated elements.”.

Alternatively you can bind the functionality to a keyboard shortcut (I personally like mapping it to CRTL+/).

A second helper function (format_all_paths()) formats all here() and file.path() calls in the active file, while also allowing users to define additional function calls to target using the fns argument.

# Open the document in RStudio and then run the following from the console
format_all_paths()

# To only target here() calls
format_all_paths(fns = c("here"))

# To only target file.path() calls
format_all_paths(fns = c("file.path"))

Motivation

My primary motivation for this project was to make it as easy as possible to use the here::here() workflow (the benefits of which are laid out in a README by @jennybc). This package/AddIn was created to address my sole issue with here(), in that its a pain to format auto-completed file paths by manually going from a slash-separated string to quoted, comma-separated elements.

In addition, this project presented a good opportunity to explore three topics I was keen to expand my knowledge of:

  • the RStudio interface (accessed via the rstudioapi package), in particular developing tests for functions that modify user-highlighted text/the active file;
  • building RStudio AddIns; and
  • regex syntax, particularly around the handling of slashes (“\” and “/”).

[1] This is to prevent users (mainly me) from reformatting paths in functions that do not support separator-agnostic file paths.

About

Auto-complete your file path natively in RStudio, then use the {pathformatr} add-in to quickly reformat your path for use with here::here() or file.path()

mcguinlu.github.io/pathformatr/

Topics

rrstudiorstudio-addin

Resources

Readme
Activity

Stars

14 stars

Watchers

1 watching

Forks

2 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.