Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ewenme committed Aug 3, 2017
0 parents commit 8b20f6f
Show file tree
Hide file tree
Showing 12 changed files with 396 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .Rbuildignore
@@ -0,0 +1,4 @@
^packrat/
^\.Rprofile$
^.*\.Rproj$
^\.Rproj\.user$
3 changes: 3 additions & 0 deletions .Rprofile
@@ -0,0 +1,3 @@
#### -- Packrat Autoloader (version 0.4.8-1) -- ####
source("packrat/init.R")
#### -- End Packrat Autoloader -- ####
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
packrat/lib*/
.Rproj.user
11 changes: 11 additions & 0 deletions DESCRIPTION
@@ -0,0 +1,11 @@
Package: ghibli
Type: Package
Title: What the Package Does (Title Case)
Version: 0.1.0
Author: Who wrote it
Maintainer: The package maintainer <yourself@somewhere.net>
Description: More about what it does (maybe more than one line)
Use four spaces when indenting paragraphs within the Description.
License: What license is it under?
Encoding: UTF-8
LazyData: true
1 change: 1 addition & 0 deletions NAMESPACE
@@ -0,0 +1 @@
exportPattern("^[[:alpha:]]+")
98 changes: 98 additions & 0 deletions R/colours.R
@@ -0,0 +1,98 @@
#' Complete list of palettes
#'
#' Use \code{\link{wes_palette}} to construct palettes of desired length.
#'
#' @export
ghibli_palettes <- list(
MarnieLight1 = c("#A42820", "#5F5647", "#9B110E", "#3F5151", "#4E2A1E", "#550307", "#0C1707"),
MarnieMedium1 = c("#FAD510", "#CB2314", "#273046", "#354823", "#1E1E1E"),
MarnieDark1 = c("#E1BD6D", "#EABE94", "#0B775E", "#35274A" ,"#F2300F"),
MarnieLight2 = c("#A42820", "#5F5647", "#9B110E", "#3F5151", "#4E2A1E", "#550307", "#0C1707"),
MarnieMedium2 = c("#FAD510", "#CB2314", "#273046", "#354823", "#1E1E1E"),
MarnieDark2 = c("#E1BD6D", "#EABE94", "#0B775E", "#35274A" ,"#F2300F"),
PonyoLight = c("#899DA4", "#C93312", "#FAEFD1", "#DC863B"),
PonyoMedium = c("#9A8822", "#F5CDB4", "#F8AFA8", "#FDDDA0", "#74A089"),
PonyoDark = c("#3B9AB2", "#78B7C5", "#EBCC2A", "#E1AF00", "#F21A00"),
LaputaLight = c("#FF0000", "#00A08A", "#F2AD00", "#F98400", "#5BBCD6"),
LaputaMedium = c("#ECCBAE", "#046C9A", "#D69C4E", "#ABDDDE", "#000000"),
LaputaDark = c("#446455", "#FDD262", "#D3DDDC", "#C7B19C"),
MononokeLight = c("#DD8D29", "#E2D200", "#46ACC8", "#E58601", "#B40F20"),
MononokeMedium = c("#F3DF6C", "#CEAB07", "#D5D5D3", "#24281A"),
MononokeDark = c("#798E87", "#C27D38", "#CCC591", "#29211F"),
SpiritedLight = c("#85D4E3", "#F4B5BD", "#9C964A", "#CDC08C", "#FAD77B"),
SpiritedMedium = c("#D8B70A", "#02401B", "#A2A475", "#81A88D", "#972D15"),
SpiritedDark = c("#F1BB7B", "#FD6467", "#5B1A18", "#D67236"),
YesterdayLight = c("#E6A0C4", "#C6CDF7", "#D8A499", "#7294D4"),
YesterdayMedium = c("#E6A0C4", "#C6CDF7", "#D8A499", "#7294D4"),
YesterdayDark = c("#E6A0C4", "#C6CDF7", "#D8A499", "#7294D4")

)

#' A Wes Anderson palette generator
#'
#' These are a handful of color palettes from Wes Anderson movies.
#'
#' @param n Number of colors desired. Unfortunately most palettes now only
#' have 4 or 5 colors. But hopefully we'll add more palettes soon. All color
#' schemes are derived from the most excellent Tumblr blog:
#' \href{http://wesandersonpalettes.tumblr.com/}{Wes Anderson Palettes}.
#' If omitted, uses all colours.
#' @param name Name of desired palette. Choices are:
#' \code{BottleRocket1}, \code{BottleRocket2}, \code{Rushmore1},
#' \code{Royal1}, \code{Royal2}, \code{Zissou1}, \code{Darjeeling1},
#' \code{Darjeeling2}, \code{Chevalier1} , \code{FantasticFox1} ,
#' \code{Moonrise1}, \code{Moonrise2}, \code{Moonrise3}, \code{Cavalcanti1},
#' \code{GrandBudapest1}, \code{GrandBudapest2}
#' @param type Either "continuous" or "discrete". Use continuous if you want
#' to automatically interpolate between colours.
#' @importFrom graphics rgb rect par image text
#' @return A vector of colours.
#' @export
#' @keywords colors
#' @examples
#' wes_palette("Royal1")
#' wes_palette("GrandBudapest1")
#' wes_palette("Cavalcanti1")
#' wes_palette("Cavalcanti1", 3)
#'
#' # If you need more colours than normally found in a palette, you
#' # can use a continuous palette to interpolate between existing
#' # colours
#' pal <- wes_palette(21, name = "Zissou1", type = "continuous")
#' image(volcano, col = pal)
wes_palette <- function(name, n, type = c("discrete", "continuous")) {
type <- match.arg(type)

pal <- wes_palettes[[name]]
if (is.null(pal))
stop("Palette not found.")

if (missing(n)) {
n <- length(pal)
}

if (type == "discrete" && n > length(pal)) {
stop("Number of requested colors greater than what palette can offer")
}

out <- switch(type,
continuous = grDevices::colorRampPalette(pal)(n),
discrete = pal[1:n]
)
structure(out, class = "palette", name = name)
}

#' @export
#' @importFrom graphics rect par image text
#' @importFrom grDevices rgb
print.palette <- function(x, ...) {
n <- length(x)
old <- par(mar = c(0.5, 0.5, 0.5, 0.5))
on.exit(par(old))

image(1:n, 1, as.matrix(1:n), col = x,
ylab = "", xaxt = "n", yaxt = "n", bty = "n")

rect(0, 0.9, n + 1, 1.1, col = rgb(1, 1, 1, 0.8), border = NA)
text((n + 1) / 2, 1, labels = attr(x, "name"), cex = 1, family = "serif")
}
20 changes: 20 additions & 0 deletions ghibli.Rproj
@@ -0,0 +1,20 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
12 changes: 12 additions & 0 deletions man/hello.Rd
@@ -0,0 +1,12 @@
\name{hello}
\alias{hello}
\title{Hello, World!}
\usage{
hello()
}
\description{
Prints 'Hello, world!'.
}
\examples{
hello()
}
217 changes: 217 additions & 0 deletions packrat/init.R
@@ -0,0 +1,217 @@
local({

## Helper function to get the path to the library directory for a
## given packrat project.
getPackratLibDir <- function(projDir = NULL) {
path <- file.path("packrat", "lib", R.version$platform, getRversion())

if (!is.null(projDir)) {

## Strip trailing slashes if necessary
projDir <- sub("/+$", "", projDir)

## Only prepend path if different from current working dir
if (!identical(normalizePath(projDir), normalizePath(getwd())))
path <- file.path(projDir, path)
}

path
}

## Ensure that we set the packrat library directory relative to the
## project directory. Normally, this should be the working directory,
## but we also use '.rs.getProjectDirectory()' if necessary (e.g. we're
## rebuilding a project while within a separate directory)
libDir <- if (exists(".rs.getProjectDirectory"))
getPackratLibDir(.rs.getProjectDirectory())
else
getPackratLibDir()

## Unload packrat in case it's loaded -- this ensures packrat _must_ be
## loaded from the private library. Note that `requireNamespace` will
## succeed if the package is already loaded, regardless of lib.loc!
if ("packrat" %in% loadedNamespaces())
try(unloadNamespace("packrat"), silent = TRUE)

if (suppressWarnings(requireNamespace("packrat", quietly = TRUE, lib.loc = libDir))) {

# Check 'print.banner.on.startup' -- when NA and RStudio, don't print
print.banner <- packrat::get_opts("print.banner.on.startup")
if (print.banner == "auto" && is.na(Sys.getenv("RSTUDIO", unset = NA))) {
print.banner <- TRUE
} else {
print.banner <- FALSE
}
return(packrat::on(print.banner = print.banner))
}

## Escape hatch to allow RStudio to handle bootstrapping. This
## enables RStudio to provide print output when automagically
## restoring a project from a bundle on load.
if (!is.na(Sys.getenv("RSTUDIO", unset = NA)) &&
is.na(Sys.getenv("RSTUDIO_PACKRAT_BOOTSTRAP", unset = NA))) {
Sys.setenv("RSTUDIO_PACKRAT_BOOTSTRAP" = "1")
setHook("rstudio.sessionInit", function(...) {
# Ensure that, on sourcing 'packrat/init.R', we are
# within the project root directory
if (exists(".rs.getProjectDirectory")) {
owd <- getwd()
setwd(.rs.getProjectDirectory())
on.exit(setwd(owd), add = TRUE)
}
source("packrat/init.R")
})
return(invisible(NULL))
}

## Bootstrapping -- only performed in interactive contexts,
## or when explicitly asked for on the command line
if (interactive() || "--bootstrap-packrat" %in% commandArgs(TRUE)) {

message("Packrat is not installed in the local library -- ",
"attempting to bootstrap an installation...")

## We need utils for the following to succeed -- there are calls to functions
## in 'restore' that are contained within utils. utils gets loaded at the
## end of start-up anyhow, so this should be fine
library("utils", character.only = TRUE)

## Install packrat into local project library
packratSrcPath <- list.files(full.names = TRUE,
file.path("packrat", "src", "packrat")
)

## No packrat tarballs available locally -- try some other means of installation
if (!length(packratSrcPath)) {

message("> No source tarball of packrat available locally")

## There are no packrat sources available -- try using a version of
## packrat installed in the user library to bootstrap
if (requireNamespace("packrat", quietly = TRUE) && packageVersion("packrat") >= "0.2.0.99") {
message("> Using user-library packrat (",
packageVersion("packrat"),
") to bootstrap this project")
}

## Couldn't find a user-local packrat -- try finding and using devtools
## to install
else if (requireNamespace("devtools", quietly = TRUE)) {
message("> Attempting to use devtools::install_github to install ",
"a temporary version of packrat")
library(stats) ## for setNames
devtools::install_github("rstudio/packrat")
}

## Try downloading packrat from CRAN if available
else if ("packrat" %in% rownames(available.packages())) {
message("> Installing packrat from CRAN")
install.packages("packrat")
}

## Fail -- couldn't find an appropriate means of installing packrat
else {
stop("Could not automatically bootstrap packrat -- try running ",
"\"'install.packages('devtools'); devtools::install_github('rstudio/packrat')\"",
"and restarting R to bootstrap packrat.")
}

# Restore the project, unload the temporary packrat, and load the private packrat
packrat::restore(prompt = FALSE, restart = TRUE)

## This code path only reached if we didn't restart earlier
unloadNamespace("packrat")
requireNamespace("packrat", lib.loc = libDir, quietly = TRUE)
return(packrat::on())

}

## Multiple packrat tarballs available locally -- try to choose one
## TODO: read lock file and infer most appropriate from there; low priority because
## after bootstrapping packrat a restore should do the right thing
if (length(packratSrcPath) > 1) {
warning("Multiple versions of packrat available in the source directory;",
"using packrat source:\n- ", shQuote(packratSrcPath))
packratSrcPath <- packratSrcPath[[1]]
}


lib <- file.path("packrat", "lib", R.version$platform, getRversion())
if (!file.exists(lib)) {
dir.create(lib, recursive = TRUE)
}
lib <- normalizePath(lib, winslash = "/")

message("> Installing packrat into project private library:")
message("- ", shQuote(lib))

surround <- function(x, with) {
if (!length(x)) return(character())
paste0(with, x, with)
}

## The following is performed because a regular install.packages call can fail
peq <- function(x, y) paste(x, y, sep = " = ")
installArgs <- c(
peq("pkgs", surround(packratSrcPath, with = "'")),
peq("lib", surround(lib, with = "'")),
peq("repos", "NULL"),
peq("type", surround("source", with = "'"))
)
installCmd <- paste(sep = "",
"utils::install.packages(",
paste(installArgs, collapse = ", "),
")")

fullCmd <- paste(
surround(file.path(R.home("bin"), "R"), with = "\""),
"--vanilla",
"--slave",
"-e",
surround(installCmd, with = "\"")
)
system(fullCmd)

## Tag the installed packrat so we know it's managed by packrat
## TODO: should this be taking information from the lockfile? this is a bit awkward
## because we're taking an un-annotated packrat source tarball and simply assuming it's now
## an 'installed from source' version

## -- InstallAgent -- ##
installAgent <- 'InstallAgent: packrat 0.4.8-1'

## -- InstallSource -- ##
installSource <- 'InstallSource: source'

packratDescPath <- file.path(lib, "packrat", "DESCRIPTION")
DESCRIPTION <- readLines(packratDescPath)
DESCRIPTION <- c(DESCRIPTION, installAgent, installSource)
cat(DESCRIPTION, file = packratDescPath, sep = "\n")

# Otherwise, continue on as normal
message("> Attaching packrat")
library("packrat", character.only = TRUE, lib.loc = lib)

message("> Restoring library")
restore(restart = FALSE)

# If the environment allows us to restart, do so with a call to restore
restart <- getOption("restart")
if (!is.null(restart)) {
message("> Packrat bootstrap successfully completed. ",
"Restarting R and entering packrat mode...")
return(restart())
}

# Callers (source-erers) can define this hidden variable to make sure we don't enter packrat mode
# Primarily useful for testing
if (!exists(".__DONT_ENTER_PACKRAT_MODE__.") && interactive()) {
message("> Packrat bootstrap successfully completed. Entering packrat mode...")
packrat::on()
}

Sys.unsetenv("RSTUDIO_PACKRAT_BOOTSTRAP")

}

})
13 changes: 13 additions & 0 deletions packrat/packrat.lock
@@ -0,0 +1,13 @@
PackratFormat: 1.4
PackratVersion: 0.4.8.1
RVersion: 3.4.0
Repos: BioCsoft=https://bioconductor.org/packages/3.5/bioc,
BioCann=https://bioconductor.org/packages/3.5/data/annotation,
BioCexp=https://bioconductor.org/packages/3.5/data/experiment,
BioCextra=https://bioconductor.org/packages/3.5/extra,
CRAN=https://cran.rstudio.com/

Package: packrat
Source: CRAN
Version: 0.4.8-1
Hash: 6ad605ba7b4b476d84be6632393f5765

0 comments on commit 8b20f6f

Please sign in to comment.