- Notifications
You must be signed in to change notification settings - Fork6
RStudio add-in to copy data to clipboard, reverse slashes, insert and reformat pipes.
License
sfr/RStudio-Addin-Snippets
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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
- Reverse slashes
- Copy data to Clipboard (vectors, tables, arrays, matrices, data frames)
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.
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).
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 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.
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\columns | x | y | z |
|---|---|---|---|
| a | 1 | 4 | 7 |
| b | 2 | 5 | 8 |
| c | 3 | 6 | 9 |
mat.2 <- matrix( 1:9 , nrow=3 , dimnames=list( letters[1:3] , columns=letters[24:26] ) )| \columns | x | y | z |
|---|---|---|---|
| a | 1 | 4 | 7 |
| b | 2 | 5 | 8 |
| c | 3 | 6 | 9 |
mat.3 <- matrix( 1:9 , nrow=3 , dimnames=list( rows=letters[1:3] , letters[24:26] ) )| rows\ | x | y | z |
|---|---|---|---|
| a | 1 | 4 | 7 |
| b | 2 | 5 | 8 |
| c | 3 | 6 | 9 |
mat.4 <- matrix( 1:9 , nrow=3 , dimnames=list( letters[1:3] , letters[24:26] ) )| mat.4 | x | y | z |
|---|---|---|---|
| a | 1 | 4 | 7 |
| b | 2 | 5 | 8 |
| c | 3 | 6 | 9 |
Data frames act asmatrices.
1D arrays act asvectors.
2D arrays act asmatrices.
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.
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 24In clipboard:
| x | z | arr.3d | |
|---|---|---|---|
| a | k | x | 1 |
| b | k | x | 2 |
| c | k | x | 3 |
| a | l | x | 4 |
| b | l | x | 5 |
| c | l | x | 6 |
| a | m | x | 7 |
| b | m | x | 8 |
| c | m | x | 9 |
| a | n | x | 10 |
| b | n | x | 11 |
| c | n | x | 12 |
| a | k | y | 13 |
| b | k | y | 14 |
| c | k | y | 15 |
| a | l | y | 16 |
| b | l | y | 17 |
| c | l | y | 18 |
| a | m | y | 19 |
| b | m | y | 20 |
| c | m | y | 21 |
| a | n | y | 22 |
| b | n | y | 23 |
| c | n | y | 24 |
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 24In clipboard:
- the empty top row won't be in the output - markdown doesn't support tableswithout headers
| a | k | x | 1 |
| b | k | x | 2 |
| c | k | x | 3 |
| a | l | x | 4 |
| b | l | x | 5 |
| c | l | x | 6 |
| a | m | x | 7 |
| b | m | x | 8 |
| c | m | x | 9 |
| a | n | x | 10 |
| b | n | x | 11 |
| c | n | x | 12 |
| a | k | y | 13 |
| b | k | y | 14 |
| c | k | y | 15 |
| a | l | y | 16 |
| b | l | y | 17 |
| c | l | y | 18 |
| a | m | y | 19 |
| b | m | y | 20 |
| c | m | y | 21 |
| a | n | y | 22 |
| b | n | y | 23 |
| c | n | y | 24 |
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 24In clipboard:
- the empty top row won't be in the output - markdown doesn't support tableswithout headers
| A | A | A | 1 |
| B | A | A | 2 |
| C | A | A | 3 |
| A | B | A | 4 |
| B | B | A | 5 |
| C | B | A | 6 |
| A | C | A | 7 |
| B | C | A | 8 |
| C | C | A | 9 |
| A | D | A | 10 |
| B | D | A | 11 |
| C | D | A | 12 |
| A | A | B | 13 |
| B | A | B | 14 |
| C | A | B | 15 |
| A | B | B | 16 |
| B | B | B | 17 |
| C | B | B | 18 |
| A | C | B | 19 |
| B | C | B | 20 |
| C | C | B | 21 |
| A | D | B | 22 |
| B | D | B | 23 |
| C | D | B | 24 |
"1D" tables act asvectors.
"2D" tables act asmatrices.
"3+D" tables act as3+D arrays.
About
RStudio add-in to copy data to clipboard, reverse slashes, insert and reformat pipes.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.