From a7f5a5cb5a16ef76c33088a24d70be880a1f598a Mon Sep 17 00:00:00 2001 From: Bob Rudis Date: Tue, 24 Mar 2015 01:30:02 -0400 Subject: [PATCH] bug fix --- DESCRIPTION | 4 ++-- NAMESPACE | 4 +--- R/readpal.R | 2 +- R/soc.R | 15 +++++-------- R/swatches-package.R | 5 +---- inst/palettes/cc-ooo.soc | 58 ------------------------------------------------ inst/palettes/ccooo.soc | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ man/read_soc.Rd | 10 ++++----- 8 files changed, 74 insertions(+), 82 deletions(-) delete mode 100644 inst/palettes/cc-ooo.soc create mode 100644 inst/palettes/ccooo.soc diff --git a/DESCRIPTION b/DESCRIPTION index cddb790..8acd024 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: swatches Type: Package Title: Read and Visualize Color Swatch Files -Version: 0.3 +Version: 0.3.1 Date: 2015-03-23 Author: Bob Rudis (@hrbrmstr) Maintainer: Bob Rudis @@ -20,7 +20,7 @@ Description: There are numerous places to create and download color URL: http://github.com/hrbrmstr/swatches BugReports: https://github.com/hrbrmstr/swatches/issues License: MIT + file LICENSE -NeedsCompilation: Yes +NeedsCompilation: yes Imports: httr (>= 0.6.0), pack, diff --git a/NAMESPACE b/NAMESPACE index 0c7d71a..535c415 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,11 +7,9 @@ export(read_kde) export(read_palette) export(read_soc) export(show_palette) +import(XML) import(pack) import(stringr) -importFrom(XML,xmlAttrs) -importFrom(XML,xmlParse) -importFrom(XML,xpathSApply) importFrom(httr,GET) importFrom(httr,stop_for_status) importFrom(httr,write_disk) diff --git a/R/readpal.R b/R/readpal.R index 1c31c70..22d914a 100644 --- a/R/readpal.R +++ b/R/readpal.R @@ -18,8 +18,8 @@ read_palette <- function(path, use_names=TRUE, .verbose=FALSE) { if (ext == "aco") { return(read_aco(path, use_names, .verbose)) } if (ext == "ase") { return(read_ase(path, use_names, .verbose)) } if (ext == "gpl") { return(read_gpl(path, use_names, .verbose)) } - if (ext == "kde") { return(read_kde(path, use_names, .verbose)) } if (ext == "soc") { return(read_soc(path, use_names, .verbose)) } + if (ext == "colors") { return(read_kde(path, use_names, .verbose)) } message("Unrecognized or unsupported palette file format") diff --git a/R/soc.R b/R/soc.R index 300eee6..40436ab 100644 --- a/R/soc.R +++ b/R/soc.R @@ -1,7 +1,4 @@ -# -# # cc-ooo.soc -# -# #' Read colors from OpenOffice Palette (SOC) files +#' Read colors from OpenOffice Palette (SOC) files #' #' Given a path or URL to an \code{.soc} file, this function will return #' a named character vector (if color names are present) of hex RGB colors. @@ -11,13 +8,13 @@ #' @param .verbose show extra information about GPL file processing #' @note When using named color palettes in a \code{ggplot2} \code{scale_} context, you #' must \code{unname} them or set \code{use_names} to \code{FALSE}. -#' Not sure if this is a bug or a deliberate feature in ggplot2. Also, Neither Lab nor -#' greyscale colors are supported. +#' Not sure if this is a bug or a deliberate feature in ggplot2. #' @export #' @examples #' # built-in palette -#' ccooo <- read_soc(system.file("palettes", -#' "cc-ooo.soc", package="swatches")) +#' soc_file <- system.file("palettes", "ccooo.soc", package="swatches") +#' system(sprintf("cat %s", soc_file)) +#' ccooo <- read_soc(soc_file) #' print(ccooo) #' #show_palette(ccooo) #' @@ -35,7 +32,7 @@ read_soc <- function(path, use_names=TRUE, .verbose=FALSE) { pal <- NULL - soc <- xmlParse("inst/palettes/cc-ooo.soc") + soc <- xmlParse(path) tmp <- gsub("^\ +", "", xpathSApply(soc, "//draw:color", xmlAttrs, "draw:name")) pal <- tmp[seq(2, length(tmp), 2)] names(pal) <- tmp[seq(1, length(tmp), 2)] diff --git a/R/swatches-package.R b/R/swatches-package.R index e2c6d7f..61c0222 100644 --- a/R/swatches-package.R +++ b/R/swatches-package.R @@ -1,11 +1,8 @@ #' Read color/swatch files #' @name swatches #' @docType package -#' @import pack stringr +#' @import pack stringr XML #' @importFrom tools file_ext -#' @importFrom XML xmlParse -#' @importFrom XML xpathSApply -#' @importFrom XML xmlAttrs #' @importFrom httr write_disk #' @importFrom httr GET #' @importFrom httr stop_for_status diff --git a/inst/palettes/cc-ooo.soc b/inst/palettes/cc-ooo.soc deleted file mode 100644 index fa3711c..0000000 --- a/inst/palettes/cc-ooo.soc +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/inst/palettes/ccooo.soc b/inst/palettes/ccooo.soc new file mode 100644 index 0000000..fa3711c --- /dev/null +++ b/inst/palettes/ccooo.soc @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/man/read_soc.Rd b/man/read_soc.Rd index 61c8027..f1bcb02 100644 --- a/man/read_soc.Rd +++ b/man/read_soc.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/soc.R \name{read_soc} \alias{read_soc} -\title{#Read colors from OpenOffice Palette (SOC) files} +\title{Read colors from OpenOffice Palette (SOC) files} \usage{ read_soc(path, use_names = TRUE, .verbose = FALSE) } @@ -20,13 +20,13 @@ a named character vector (if color names are present) of hex RGB colors. \note{ When using named color palettes in a \code{ggplot2} \code{scale_} context, you must \code{unname} them or set \code{use_names} to \code{FALSE}. - Not sure if this is a bug or a deliberate feature in ggplot2. Also, Neither Lab nor - greyscale colors are supported. + Not sure if this is a bug or a deliberate feature in ggplot2. } \examples{ # built-in palette -ccooo <- read_soc(system.file("palettes", - "cc-ooo.soc", package="swatches")) +soc_file <- system.file("palettes", "ccooo.soc", package="swatches") +system(sprintf("cat \%s", soc_file)) +ccooo <- read_soc(soc_file) print(ccooo) #show_palette(ccooo)