A collection of custom R functions. Helper functions complementing the new CodeAndRoll2. Many functionalities were part of the formerly used CodeAndRoll (v1).
1.) Download Rocinante.R
, save as local .R
file, and source(~/path/to/Rocinante.R)
:
2.) Directly source from the web:
source("https://raw.githubusercontent.com/vertesy/Rocinante/main/R/Rocinante.R")
If you encounter a bug, something doesn't work or unclear, please let me know by raising an issue on Rocinante – Please check if it has been asked.
Silent try
Source parts of another script. Source: https://stackoverflow.com/questions/26245554/execute-a-set-of-lines-from-another-r-file
Calculate pairwise euclidean distance
Calculate absolute value of the pairwise euclidean distance
RETURNS A LIST. Calculates the autocorrelation of each row of a numeric matrix / data frame.
RETURNS A LIST. Calculates the autocorrelation of each row of a numeric matrix / data frame.
Autocorrelation with exact lag
RETURNS A Vector for the "lag" based autocorrelation. Calculates the autocorrelation of each row of a numeric matrix / data frame.
RETURNS A Vector for the "lag" based autocorrelation. Calculates the autocorrelation of each row of a numeric matrix / data frame.
Copy from clipboard (e.g. excel) to a R-formatted vector to the clipboard
Read a comma separated string (e.g. list of gene names) and properly format it for R.
Clipboard export for da wonderful countries with where "," is the decimal
view the head of an object by console.
view the head of an object by View().
Test if names of two objects for being exactly equal
Test if two objects for being exactly equal
Test if two objects for being exactly equal.
Internal function. Checks if a variable is defined, and its value is TRUE.
https://stackoverflow.com/questions/17218404/should-i-get-a-habit-of-removing-unused-variables-in-r
Parse google search query links to your list of gene symbols. Strings "prefix" and ""suffix" will be searched for together with each gene ("Human ID4 neurons"). See many additional services in DatabaseLinke.R.
Parse bing search query links to your list of gene symbols. Strings "prefix" and ""suffix" will be searched for together with each gene ("Human ID4 neurons"). See many additional services in DatabaseLinke.R.
GC-content of a string (frequency of G and C letters among all letters).
Report at every e.g. 1000
Stop script if the condition is met. You can parse anything (e.g. variables) in the message
Use system voice to notify (after a long task is done)
Use system voice to notify (after a long task is done)
Open current working directory.
Unload a package. Source: https://stackoverflow.com/questions/6979917/how-to-unload-a-package-without-restarting-r
Load a package. If it does not exist, try to install it from CRAN.
Source: https://aurelienmadouasse.wordpress.com/2012/01/13/legend-for-a-continuous-color-scale-in-r/
This function converts a vector of values("yourdata") to a vector of color levels. One must define the number of colors. The limits of the color scale("zlim") or the break points for the color changes("breaks") can also be defined. When breaks and zlim are defined, breaks overrides zlim.
Alias for rich.colors in gplots
Display the colors encoded by the numbers / color-ID-s you pass on to this function
Draw a barplot from ColSums of a matrix.
Renders the lm() function's output into a human readable text. (e.g. for subtitles)
Renders the lm() function's output into a human readable text. (e.g. for subtitles)
Renders the lm() function's output into a human readable text. (e.g. for subtitles)
Split a one variable by another. Calculates equal bins in splitby, and returns a list of the corresponding values in toSplit.
A function to display correlation values for pairs() function. Default is pearson correlation, that can be set to "kendall" or "spearman".
A function to display correlation values for pairs() function. Default is pearson correlation, that can be set to "kendall" or "spearman".
Quantile breakpoints in any data vector http://slowkow.com/notes/heatmap-tutorial/
Extract ROW order from a pheatmap object.
Extract COLUMN order from a pheatmap object.
Extract cluster ID's for ROWS of a pheatmap object.
Extract cluster ID's for COLUMNS of a pheatmap object.
Calculate the position of ROW separating lines between clusters in a pheatmap object.
Calculate the position of COLUMN separating lines between clusters in a pheatmap object.
calculate gap positions for pheatmap, based a sorted annotation vector of categories
Create a Matlab-like color gradient using "colorRamps".
For VECTORS. Auxiliary function for pheatmap. Prepares the 2 variables needed for "annotation_col" and "annotation_colors" in pheatmap
For data frames. Auxiliary function for pheatmap. Prepares the 2 variables needed for "annotation_col" and "annotation_colors" in pheatmap
fix class and color annotation in pheatmap annotation data frame's and lists.
For data frames. Auxiliary function for pheatmap. Prepares the 2 variables needed for "annotation_col" and "annotation_colors" in pheatmap
make a backup of an object into global env. Scheme: obj > obj.bac
list dirs recursive up to a certain level in R https://stackoverflow.com/questions/48297440/list-files-recursive-up-to-a-certain-level-in-r
Parse HGNC links to your list of gene symbols.
Summary stat. text formatting for logical vectors (%, length)
Setup an A4 size jpeg