Title: | R Tools for Data Copy-Pasta |
---|---|
Description: | RStudio addins and R functions that make copy-pasting vectors and tables to text painless. |
Authors: | Miles McBain [aut, cre] , Jonathan Carroll [aut] , Mark Dulhunty [ctb], Andrew Collier [ctb], Sharla Gelfand [aut], Suthira Owlarn [aut] , Garrick Aden-Buie [aut] |
Maintainer: | Miles McBain <[email protected]> |
License: | MIT + file LICENSE |
Version: | 3.1.1 |
Built: | 2024-11-17 03:09:33 UTC |
Source: | https://github.com/milesmcbain/datapasta |
the _context functions define lists of parameters for text formatting. The specific contexts return hard-coded values appropriate to the context they describe, while custom_context allows definition of new contexts for custom formatting.
clipboard_context() rstudio_context() console_context() markdown_context() custom_context( output_mode = "console", nspc = 2, indent_context = 0, indent_head = TRUE )
clipboard_context() rstudio_context() console_context() markdown_context() custom_context( output_mode = "console", nspc = 2, indent_context = 0, indent_head = TRUE )
output_mode |
A named output mode, controls the target of the _paste functions options are "rstudioapi" or "console" |
nspc |
The number of spaces for each indent level in the output context |
indent_context |
The number of spaces applied initially to all lines in the output context |
indent_head |
Logical. Apply the indent_context to the to the header row? Use FALSE if targeting cursor location. |
an output context. An input to _paste, _format, _construct functions used to format whitespace.
Parse the current clipboard as a table and paste to the clipboard in data.frame format.
df_format(input_table, output_context = clipboard_context())
df_format(input_table, output_context = clipboard_context())
input_table |
an optional input tibble or data.frame to format. |
output_context |
an optional output context that defines the target and indentation. |
nothing.
Parse either: the current clipboard, or a supplied argument, as a table and paste in at the cursor location in data.frame format.
df_paste(input_table, output_context = guess_output_context())
df_paste(input_table, output_context = guess_output_context())
input_table |
an optional input tibble or data.frame to format. |
output_context |
an optional output context that defines the target and indentation. The default behaviour is target the rstudioapi and fall back to console if it is not available. |
nothing.
Parse the current clipboard as a table and return in data.frame format.
dfdt_construct(input_table, oc = console_context(), class = NULL)
dfdt_construct(input_table, oc = console_context(), class = NULL)
input_table |
an optional R object to parse instead of the clipboard. |
oc |
an optional output context that defines the target and indentation. |
class |
either data.frame or data.table. |
a character string containing the input formatted as a data.frame definition.
Formats input for presentation in markdown as a preformatted chunk and inserts it onto the clipboard. Ready for pasting to Stack Overflow or Github.
dmdclip(input)
dmdclip(input)
input |
a vector, data.frame, or tibble |
nothing
A function to optionally set the decimal mark if in a locale where it is not '.'. Will allow "3,14" to be parsed as 3.14, normally would be parsed as 314. Will also handle spaces in numbers.
dp_set_decimal_mark(mark)
dp_set_decimal_mark(mark)
mark |
The decimal mark to use when parsing "number" type data, as guessed by readr::guess_parser. |
NULL.
dp_set_max_rows
dp_set_max_rows(num_rows)
dp_set_max_rows(num_rows)
num_rows |
The number of rows of an input at which any of tribble_construct() or df_construct() will abort parsing. Datapasta is untested on large tables. Use at own risk. |
Formats input and inserts at either the current cursor or the console.
dpasta(input)
dpasta(input)
input |
a vector, data.frame, or tibble |
nothing
Parse the current clipboard as a table and paste to the clipboard in data.table format.
dt_format(input_table, output_context = clipboard_context())
dt_format(input_table, output_context = clipboard_context())
input_table |
an optional input tibble or data.frame to format. |
output_context |
an optional output context that defines the target and indentation. |
nothing.
Parse either: the current clipboard, or a supplied argument, as a table and paste in at the cursor location in data.table format.
dt_paste(input_table, output_context = guess_output_context())
dt_paste(input_table, output_context = guess_output_context())
input_table |
an optional input tibble or data.frame to format. |
output_context |
an optional output context that defines the target and indentation. The default behaviour is target the rstudioapi and fall back to console if it is not available. |
nothing.
Return the a list containing the guessed output target context, either rstudio or the console.
guess_output_context()
guess_output_context()
a list containing the output target, space size of indent, and number of indents at context.
Guesses the separator based on a simple heuristic over the first 10 or less rows: The separator chosen is the one that leads to the most columns, whilst parsing the same number of columns for each line (var=0). The guessing algorithm ignores blank lines - which are lines that contain only the separator. Options are in 'c(",","\t","\|",";")'
guess_sep(char_vec)
guess_sep(char_vec)
char_vec |
a table from the clipboard in character vector form. |
the separator selected to parse char_vec as a table
nchar_type
nchar_type(df_col_row, df_col_type)
nchar_type(df_col_row, df_col_type)
df_col_row |
a character string |
df_col_type |
the type the string will be converted to. |
The number of characters wide this data would be in when rendered in text
Count the number of quotes in a string
nquote_str(char_vec)
nquote_str(char_vec)
char_vec |
the string to count quotes in |
a number, possibly 0.
Left pad string to a certain size. A helper function for getting spacing in table correct.
pad_to(char_vec, char_length)
pad_to(char_vec, char_length)
char_vec |
character vector. |
char_length |
length to pad to. |
char_vec left-padded with spaces to char_length.
Pastes data from clipboard as a vertically formatted character vector on multiple lines. One line is used per element. Considers ',', 'tab', 'newline' as delimiters.
parse_vector(input_vector)
parse_vector(input_vector)
input_vector |
an optional character vector to attempt to break up, and escape. |
A vector parsed from the clipboard as ether a character string or a character vector. The type attribute contains the type guessed by 'readr'.
Similar to read_clip_tbl from clipr, however it will error if there are less than 2 rows and it tries to guess the separator.
read_clip_tbl_guess(x = NULL, ...)
read_clip_tbl_guess(x = NULL, ...)
x |
contents of the clipboard |
... |
arguments passed to read.table |
a parsed table from the clipboard. Separator is guessed.
Renders a character vector as R types for pasting into Rstudio. Strings are quoted. Numbers, NA, logicals etc are not.
render_type(char_vec, char_type)
render_type(char_vec, char_type)
char_vec |
a character vector containing text to be rendered as the type indicated by type_str |
char_type |
a string describing the type of char_vec |
A vector parsed from the clipboard as ether a character string or a character vector. The type attribute contains the type guessed by 'readr'.
Based on a type and length, render a character string as the type in text. Pad to the desired length.
render_type_pad_to(char_vec, char_type, char_length)
render_type_pad_to(char_vec, char_type, char_length)
char_vec |
a character vector |
char_type |
a string type from readr::guess_parser |
char_length |
a string length to pad to. |
a string containing the representation of char_vec as char_type in the RStudio source editor, left-padded with spaces to char_length.
wrap the datapasta around itself
tortellini(col_struct, defn_width = 80, indent_context = 0, add_comma = TRUE)
tortellini(col_struct, defn_width = 80, indent_context = 0, add_comma = TRUE)
col_struct |
input structure - a split apart column definition |
defn_width |
total number of characters in a line (includes column name and indent on line 1) |
indent_context |
the level of indent in spaces in the current editor pane |
add_comma |
add one final comma to the end of the wrapped column def? Useful when pasting together columns. |
w wrapped string
Parse the current clipboard as a table, or use the table argument supplied, and return as a character string.
tribble_construct(input_table, oc = console_context())
tribble_construct(input_table, oc = console_context())
input_table |
an optional input 'data.frame'. If 'input_table' is supplied, then nothing is read from the clipboard. |
oc |
an optional output context that defines the target and indentation. Default is console. Table is output as 'tribble()' call. Useful for creating reproducible examples. |
The parsed table text.
Parse the current clipboard as a table, or use the table argument supplied, and paste to the clipboard in tribble format.
tribble_format(input_table, output_context = console_context())
tribble_format(input_table, output_context = console_context())
input_table |
an optional input 'data.frame'. If 'input_table' is supplied, then nothing is read from the clipboard. |
output_context |
an optional output context that defines the target and indentation. Default is console. Table is output as 'tribble()' call. Useful for creating reproducible examples. |
Nothing.
Parse the current clipboard as a table, or use the table argument supplied, and paste in at the cursor location in tribble format.
tribble_paste(input_table, output_context = guess_output_context())
tribble_paste(input_table, output_context = guess_output_context())
input_table |
an optional input 'data.frame'. If 'input_table' is supplied, then nothing is read from the clipboard. |
output_context |
an optional output context that defines the target and indentation. Default is to guess between rstudio and console. Table is output as 'tribble()' call. Useful for creating reproducible examples. |
Nothing.
Returns a formatted character string, either from clipboard or supplied argument, as a vector definition. Considers ',', 'tab', 'newline' as delimiters. If a single character string is passed as an argument, it will be split to form a vector.
vector_construct(input_vector, oc = console_context())
vector_construct(input_vector, oc = console_context())
input_vector |
An input vector to be formatted for output. If supplied, no data is read from the clipboard. |
oc |
an optional output context that defines the output indentation. |
A string containing the input formatted as a vector definition.
Returns a formatted string, either from clipboard or supplied argument, as a vertically formatted character vector over many lines. Considers ',', 'tab', 'newline' as delimiters. If a single character string is passed as an argument, it will be split to form a vector.
vector_construct_vertical(input_vector, oc = console_context())
vector_construct_vertical(input_vector, oc = console_context())
input_vector |
An input vector to be formatted for output. If supplied, no data is read from the clipboard. |
oc |
an optional output context that defines the output target and indentation. The default behaviour is to target the rstudioapi and fall back to console if it is not available. |
a string containing the input formatted as a vector definition.
Writes data to the clipboard, either from clipboard or supplied argument. Writes a horizontally formatted character vector on a single line. Considers ',', 'tab', 'newline' as delimiters. If a single character string is passed as an argument, it will be split to form a vector.
vector_format(input_vector, output_context = console_context())
vector_format(input_vector, output_context = console_context())
input_vector |
An input vector to be formatted for output. If supplied, no data is read from the clipboard. |
output_context |
an optional output context that defines the output indentation. |
nothing.
Writes data to clipboard, either from clipboard or supplied argument, as a vertically formatted character vector over many lines. Considers ',', 'tab', 'newline' as delimiters. If a single character string is passed as an argument, it will be split to form a vector.
vector_format_vertical(input_vector, output_context = clipboard_context())
vector_format_vertical(input_vector, output_context = clipboard_context())
input_vector |
An input vector to be formatted for output. If supplied, no data is read from the clipboard. |
output_context |
an optional output context that defines the output target and indentation. The default behaviour is to target the rstudioapi and fall back to console if it is not available. |
nothing.
Pastes data, either from clipboard or supplied argument, as a horizontally formatted character vector on a single line. Considers ',', 'tab', 'newline' as delimiters. If a single character string is passed as an argument, it will be split to form a vector.
vector_paste(input_vector, output_context = guess_output_context())
vector_paste(input_vector, output_context = guess_output_context())
input_vector |
An input vector to be formatted for output. If supplied, no data is read from the clipboard. |
output_context |
an optional output context that defines the output target and indentation. The default behaviour is to target the rstudioapi and fall back to console if it is not available. |
nothing.
Pastes data, either from clipboard or supplied argument, as a vertically formatted character vector over many lines. Considers ',', 'tab', 'newline' as delimiters. If a single character string is passed as an argument, it will be split to form a vector.
vector_paste_vertical(input_vector, output_context = guess_output_context())
vector_paste_vertical(input_vector, output_context = guess_output_context())
input_vector |
An input vector to be formatted for output. If supplied, no data is read from the clipboard. |
output_context |
an optional output context that defines the output target and indentation. The default behaviour is to target the rstudioapi and fall back to console if it is not available. |
nothing.
An addin to fiddle your RStudio selections to better things. Make a selection in RStudio and dfiddle will update it inline. Good for: Converting Text to vectors ('c()'), pivoting between horizontal and vertical vectors, reflowing tribble() and data.frame() definitions to have nice indenting and padding.
zzz_rs_dfiddle()
zzz_rs_dfiddle()
a fiddled version of your selection (invisibly)
An addin to toggle between quotes and bare vectors. Applies to a vector selected in an RStudio source editor. Works with horizontal or vertical form.
zzz_rs_toggle_quotes()
zzz_rs_toggle_quotes()
The toggled vector (invisibly).