MyNixOS website logo
Description

Create Custom 'Rstudio' Keyboard Shortcuts.

Create custom keyboard shortcuts to examine code selected in the 'Rstudio' editor. F3 can for example yield 'str(selection)' and F7 open the source code of CRAN and base package functions on 'github'.

rskey

rstudio addins for Keyboard shortcuts

Rstudio addins to examine selected code in the Rstudio editor.
Berry Boessenkool ([email protected]), May 2017, with selectobject code idea from digital-dharma/RStudioAddIns).

I find it very useful to bind the addins to keyboard shortcuts like this (and label the keyboard):

  • F3 - structure of an object - str(selected_code)
  • F4 - head of an object - head(selected_code)
  • F5 - tail of an object - tail(selected_code)
  • F6 - View an object - View(selected_code)
  • F7 - funSource of an object - funSource(selected_code)
  • F8 - summary of an object - summary(selected_code)
  • F9 - dim of an object - dim(selected_code)
  • F10 - class of an object - class(selected_code)
  • F11 - plot an object - plot(selected_code, las=1)
  • F12 - histogram of an object - hist(selected_code, col="moccasin", breaks=50, las=1)

To use such keyboard shortcuts, follow these instructions:

if(!requireNamespace("remotes")) install.packages("remotes")
remotes::install_github("brry/rskey")

# either set all bindings:
rskey::setKeyboardBindings(overwrite=TRUE)
# by default also sets CTRL+Y for ReDo and CTRL+H for setWorkingDirToActiveDoc

# or manually:
# Rstudio - Tools - Modify Keyboard Shortcurts
# click on an addin shortcut field and press the desired key combination
# (Restart Rstudio)

funSource

funSource provides an easy option to open the source code of a function in a browser window.
Through github, there are nice syntax highlighting and search options.

find package

funSource(someFunction) tries to find the corresponding package to the input function.
You can also explicitly request funSource("somePackage::someFunction").
This works even if the package is not installed (in which case you do need the quotation marks).

open urls

In the default browser, it the opens the first link if it exists, the second if not:

  • github.com/cran/somePackage/blob/master/R/someFunction.R (or .r file)
  • github.com/search?q=someFunction function repo:cran/somePackage+path:R

The second link is a github search query needed when a function is defined in a file with a different name.
Functions in the base R packages will be searched in the wch/r-source/src/library repo.

limits

Currently, the funSource-initiated github search doesn't find names or dimnames in base R. Any idea to solve this kind of limitation is welcome!

origin

funSource is imported from berryFunctions.

examples

Examples on links opened by funSource:

Functions in CRAN packages - spatstat::rescale:
https://github.com/cran/spatstat/blob/master/R/rescale.R
https://github.com/search?q=rescale function repo:cran/spatstat+path:R

Functions in base packages - graphics::hist:
https://github.com/wch/r-source/tree/trunk/src/library/graphics/R/hist.R
https://github.com/search?q=hist function repo:wch/r-source+path:src/library/graphics/R.

Metadata

Version

0.4.4

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows