Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

RStudio add-in to copy data to clipboard, reverse slashes, insert and reformat pipes.

License

NotificationsYou must be signed in to change notification settings

sfr/RStudio-Addin-Snippets

Repository files navigation

Travis-CI Build StatusIssue CountcodecovCRAN version

RStudio add-in to add some code snippets, or help with code editing.It is aimed to be used on Windows. It requires RStudio (>= 0.99.1111) and rstudioapi (>= 0.5-1).

Currently it contains following functions:

Insert and reformat pipe

This functionality inserts pipes at the current position(s) of the cursor(s)or replaces all selections. It reformats pipe(s) surroundings to achievefollowing format:

sub <- data %>%    select(column.1, column.2) %>%        filter(column.1 > x) %>%            group_by(column.1) %>%                summarise(n=n_distinct(column.2)) %>%                    ungroup
  • exactly one space before %>%
  • line cannot start with %>% (unless it is first line of the file).
    • It will find last non-empty line before the cursor position.
  • new line after %>%
  • next line will be indented as the current line is + N spaces;
    • where N is dependent on the RStudio settings
  • then it's followed by the next word, or it is the end of the line.

Reverse slashes

This functionality is especially useful, when copying paths in Windows.

It will reverse all slashes eitherin the selected block(s) of code,or if there is no selection (or only whitespace is selected), it will reverseall slashes in the clipboard andpaste it to the current cursor(s) position(s).

Copy data to clipboard

At the moment this is Windows only function.

Function will copy the content of the variable 'under the cursor' intothe clipboard. It will be represented as atab separated value for an easypaste to MS Excel.

There is no need to precisely select the name of the variable. Cursor can beplaced anywhere in the name, or variable name needs to be first valid namein the code selection. Add-in will adjust the selection. In the case that it isnot possible to generate tsv, message will be written to the console. Otherwisetsv will be 'silently' copied to clipboard without any messages.

At the moment following data structures are supported:

Vectors

Vectors are represented in a horizontal fashion. If they are named, then firstrow will contain names and second values. If they are unnamed then only one rowwith values is copied into the clipboard.

Matrices

Value copied to clipboard will either haveM x N or(M+1) x N,M x (N+1) or(M+1) x (N+1) cells, whereM andN are matrixdimensions. If matrix has specified columns names and/or rows names than theywill be displayed in the first column and/or row.

In the case that both columns' names and rows' names are specified, the contentof the top left cell will be constructed from dimensions' names, if they exist;in the following format: Rows names dimension name, backslash, columns namesdimension name. Examples below shows all cases. If dimensions are not named,then variable name will be used.

mat.1 <- matrix( 1:9               , nrow=3               , dimnames=list( rows=letters[1:3]                              , columns=letters[24:26]                              )               )
rows\columnsxyz
a147
b258
c369
mat.2 <- matrix( 1:9               , nrow=3               , dimnames=list(         letters[1:3]                              , columns=letters[24:26]                              )               )
\columnsxyz
a147
b258
c369
mat.3 <- matrix( 1:9               , nrow=3               , dimnames=list( rows=letters[1:3]                              ,      letters[24:26]                              )               )
rows\xyz
a147
b258
c369
mat.4 <- matrix( 1:9               , nrow=3               , dimnames=list( letters[1:3]                              , letters[24:26]                              )               )
mat.4xyz
a147
b258
c369

Data frames

Data frames act asmatrices.

Arrays

1D arrays

1D arrays act asvectors.

2D arrays

2D arrays act asmatrices.

3+D arrays

3+D arrays will be flatten into amatrix. Matrix will haveN+1columns whereN is a number of dimensions andM orM+1 rows, whereM isa product of array dimensions. E.g. if array has following dimensionsdim=c(2, 4, 2), then the output table will haveN=3+1=4 columns andM=242=16 rows. If array dimensions are named, then header row will be added.FirstN columns will be take names from dimensions' names and the last columnwill be named after variable. Missing names will stay empty.

See examples below.

Example 1

3D array with defined dimension names. One of the dimension names is missing.

(arr.3d <- array( 1:24                , dim=c(3, 4, 2)                , dimnames=list( x=c('a', 'b', 'c')                               ,   c('k', 'l', 'm', 'n')                               , z=c('x', 'y')                               )                ))

Print out:

, , z = xx   k l m  n  a 1 4 7 10  b 2 5 8 11  c 3 6 9 12, , z = yx    k  l  m  n  a 13 16 19 22  b 14 17 20 23  c 15 18 21 24

In clipboard:

xzarr.3d
akx1
bkx2
ckx3
alx4
blx5
clx6
amx7
bmx8
cmx9
anx10
bnx11
cnx12
aky13
bky14
cky15
aly16
bly17
cly18
amy19
bmy20
cmy21
any22
bny23
cny24
Example 2

3D array without named dimensions.

(arr.3d <- array( 1:24                , dim=c(3, 4, 2)                , dimnames=list( c('a', 'b', 'c')                               , c('k', 'l', 'm', 'n')                               , c('x', 'y')                               )                ))

Print out:

, , x  k l m  na 1 4 7 10b 2 5 8 11c 3 6 9 12, , y   k  l  m  na 13 16 19 22b 14 17 20 23c 15 18 21 24

In clipboard:

  • the empty top row won't be in the output - markdown doesn't support tableswithout headers
akx1
bkx2
ckx3
alx4
blx5
clx6
amx7
bmx8
cmx9
anx10
bnx11
cnx12
aky13
bky14
cky15
aly16
bly17
cly18
amy19
bmy20
cmy21
any22
bny23
cny24
Example 3

Bare 3D array.

(arr.3d <- array(1:24, dim=c(3, 4, 2)))

Print out:

, , 1     [,1] [,2] [,3] [,4][1,]    1    4    7   10[2,]    2    5    8   11[3,]    3    6    9   12, , 2     [,1] [,2] [,3] [,4][1,]   13   16   19   22[2,]   14   17   20   23[3,]   15   18   21   24

In clipboard:

  • the empty top row won't be in the output - markdown doesn't support tableswithout headers
AAA1
BAA2
CAA3
ABA4
BBA5
CBA6
ACA7
BCA8
CCA9
ADA10
BDA11
CDA12
AAB13
BAB14
CAB15
ABB16
BBB17
CBB18
ACB19
BCB20
CCB21
ADB22
BDB23
CDB24

Tables

"1D" tables

"1D" tables act asvectors.

"2D" tables

"2D" tables act asmatrices.

"3+D" tables

"3+D" tables act as3+D arrays.

Collection of badges

Repository sizePending Pull-Requestsdownloadsrelease versionlicense

About

RStudio add-in to copy data to clipboard, reverse slashes, insert and reformat pipes.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp