This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Get R package information from CRAN | |
#' | |
#' \code{get_pkg_info()} retrieves the description of a CRAN package; it is | |
#' adapted from \url{http://developer.r-project.org/CRAN/Scripts/depends.R}. | |
#' Results are cached per R session using the | |
#' \href{https://cran.r-project.org/web/packages/memoise/index.html}{memoise} | |
#' package. | |
#' | |
#' @param pkg Package name (as a string) | |
#' @param fields Package description fields (as a vector); it corresponds to |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fully resolve plot labels using lazyeval | |
# Get the body of a function with values in place of object names | |
body_text <- function(f) { | |
nms <- as.list(environment(f), all.names = TRUE) | |
deparse(lazyeval::interp(body(f), .values = nms)) | |
} | |
# Functionality of body_text() implemented in base R | |
body_text_oldschool <- function(f) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Automatically assign missing names in a list or vector | |
#' | |
#' \code{fill_in_names()} supplies missing names in a list or vector according | |
#' to the following rule: if component \code{n} of \code {x} is missing, then it | |
#' is given the name \code{paste0(nm_prefix, n)}, where the prefix string | |
#' \code{nm_prefix} has the default value \code{..} (to reduce the chance of | |
#' conflicts with existing names). | |
#' | |
#' @param x A list or vector. | |
#' @param nm_prefix A string that is used to prefix generated names. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python-style tuple unpacking for lists (Gabor Grothendieck) | |
# | |
# unpack[...] is syntactic sugar for R that enables you to do Python-style | |
# tuple unpacking for lists. This is handy when a function returns multiple | |
# values in the form of a list, and you want assign those values to | |
# individual names. | |
# | |
# NB: As in Python, unpacking is done by position. | |
# | |
# Reference: https://stat.ethz.ch/pipermail/r-help/2004-June/053343.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Won't pass R CMD check because of call to internal function | |
do_try_catch <- function(expr, env) { | |
.Internal(.addCondHands("error", list(identity), env, environment(), FALSE)) | |
expr | |
} | |
# Return value of expression, or error object in case of failure | |
try_return_error <- function(expr) { | |
env <- parent.frame() | |
value <- do_try_catch(return(expr), env) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Partial function application | |
#' | |
#' @param ...f Function to partially apply. | |
#' @return Function of `...` that partially applies `...f`. (However, if no | |
#' argument values are set, `...f` is simply returned.) | |
#' | |
#' @details `partial()` resolves an error in [purrr::partial()], see purrr | |
#' issue [349](https://github.com/tidyverse/purrr/issues/349). The `.env`, | |
#' `.lazy`, `.first` arguments are dropped. | |
#' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RESET="\[\033[0m\]" | |
BLUE="\[\033[01;34m\]" | |
GREEN="\[\033[1;32m\]" | |
YELLOW="\[\033[0;33m\]" | |
prompt_command () { | |
PS_BRANCH="" | |
ref=$(git symbolic-ref HEAD 2> /dev/null) || return | |
PS_BRANCH=" (git:${ref#refs/heads/})" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Signature-preserving function composition | |
library(rlang) | |
# Variation of purrr::compose() that: | |
# - matches the formals to that of the first called function | |
# - supports unsplicing of a list of functions | |
compose <- function(...) { | |
fs <- lapply(dots_list(...), as_function) | |
n <- length(fs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; http://bit.ly/2iIFUNd | |
(setq display-buffer-alist '(("\\`\\*e?shell" display-buffer-pop-up-window))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* R.css | |
* | |
* Copyright (C) 2009-16 by RStudio, Inc. | |
* | |
* Unless you have received this program directly from RStudio pursuant | |
* to the terms of a commercial license agreement with RStudio, then | |
* this program is licensed to you under the terms of version 3 of the | |
* GNU Affero General Public License. This program is distributed WITHOUT | |
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, |
OlderNewer