Skip to content

Commit

Permalink
Export functions needed for extensions.
Browse files Browse the repository at this point in the history
Closes #1235
  • Loading branch information
hadley committed Aug 4, 2015
1 parent 8afd847 commit 93ab9e0
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 16 deletions.
5 changes: 5 additions & 0 deletions NAMESPACE
Expand Up @@ -142,6 +142,8 @@ S3method(widthDetails,titleGrob)
S3method(widthDetails,zeroGrob)
export("%+%")
export("%+replace%")
export(.pt)
export(.stroke)
export(ContinuousRange)
export(Coord)
export(CoordCartesian)
Expand Down Expand Up @@ -248,6 +250,7 @@ export(coord_equal)
export(coord_fixed)
export(coord_flip)
export(coord_map)
export(coord_munch)
export(coord_polar)
export(coord_quickmap)
export(coord_trans)
Expand Down Expand Up @@ -367,6 +370,7 @@ export(position_stack)
export(qplot)
export(quickplot)
export(rel)
export(remove_missing)
export(resolution)
export(scale_alpha)
export(scale_alpha_continuous)
Expand Down Expand Up @@ -483,6 +487,7 @@ export(xlab)
export(xlim)
export(ylab)
export(ylim)
export(zeroGrob)
import(grid)
import(gtable)
import(scales)
Expand Down
13 changes: 13 additions & 0 deletions R/coord-munch.r
@@ -1,3 +1,16 @@
#' Munch coordinates data
#'
#' This function "munches" lines, dividing each line into many small pieces
#' so they can be transformed independently. Used inside geom functions.
#'
#' @param coord Coordinate system definition.
#' @param data Data set to transform - should have variables \code{x} and
#' \code{y} are chopped up into small pieces (as defined by \code{group}).
#' All other variables are duplicated as needed.
#' @param range Panel range specification.
#' @param segment_length Target segment length
#' @keywords internal
#' @export
coord_munch <- function(coord, data, range, segment_length = 0.01) {
if (coord$is_linear()) return(coord$transform(data, range))

Expand Down
13 changes: 12 additions & 1 deletion R/geom-.r
@@ -1,10 +1,21 @@
#' @include legend-draw.r
NULL

#' Graphical units
#'
#' Multiply size in mm by these constants in order to convert to the units
#' that grid uses internally for \code{lwd} and \code{fontsize}.
#'
#' @name graphical-units
NULL

#' @export
#' @rdname graphical-units
.pt <- 1 / 0.352777778
#' @export
#' @rdname graphical-units
.stroke <- 96 / 25.4


#' @section Geoms:
#'
#' All \code{geom_*} functions (like \code{geom_point}) return a layer that
Expand Down
1 change: 1 addition & 0 deletions R/grob-null.r
@@ -1,6 +1,7 @@
#' The zero grob draws nothing and has zero size.
#'
#' @keywords internal
#' @export
zeroGrob <- function() .zeroGrob

.zeroGrob <- grob(cl = "zeroGrob", name = "NULL")
Expand Down
30 changes: 15 additions & 15 deletions R/utilities.r
Expand Up @@ -97,19 +97,21 @@ safe.call <- function(f, params, f.params = names(formals(f)), ignore.dots = TRU
do.call(f, safe.params)
}

# Convenience function to remove missing values from a data.frame
# Remove all non-complete rows, with a warning if \code{na.rm = FALSE}.
#
# ggplot is somewhat more accommodating of missing values than R generally.
# For those stats which require complete data, missing values will be
# automatically removed with a warning. If \code{na.rm = TRUE} is supplied
# to the statistic, the warning will be suppressed.
#
# @param data.frame
# @param suppress warning that rows are being removed?
# @argumnets variables to check for missings in
# @param optional function name to make warning message more informative
# @keyword internal
#' Convenience function to remove missing values from a data.frame
#'
#' Remove all non-complete rows, with a warning if \code{na.rm = FALSE}.
#' ggplot is somewhat more accommodating of missing values than R generally.
#' For those stats which require complete data, missing values will be
#' automatically removed with a warning. If \code{na.rm = TRUE} is supplied
#' to the statistic, the warning will be suppressed.
#'
#' @param df data.frame
#' @param na.rm If true, will suppress warning message.
#' @param vars Character vector of variables to check for missings in
#' @param name Optional function name to improve error message.
#' @param finite If \code{TRUE}, will also remove non-finite values.
#' @keywords internal
#' @export
remove_missing <- function(df, na.rm=FALSE, vars = names(df), name="", finite = FALSE) {
vars <- intersect(vars, names(df))
if (name != "") name <- paste(" (", name, ")", sep = "")
Expand All @@ -128,7 +130,6 @@ remove_missing <- function(df, na.rm=FALSE, vars = names(df), name="", finite =
" values", name, ".", call. = FALSE)
}


df
}

Expand All @@ -150,7 +151,6 @@ finite.cases.data.frame <- function(x) {
}
}


# "Invert" a list
# Keys become values, values become keys
#
Expand Down
25 changes: 25 additions & 0 deletions man/coord_munch.Rd
@@ -0,0 +1,25 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/coord-munch.r
\name{coord_munch}
\alias{coord_munch}
\title{Munch coordinates data}
\usage{
coord_munch(coord, data, range, segment_length = 0.01)
}
\arguments{
\item{coord}{Coordinate system definition.}

\item{data}{Data set to transform - should have variables \code{x} and
\code{y} are chopped up into small pieces (as defined by \code{group}).
All other variables are duplicated as needed.}

\item{range}{Panel range specification.}

\item{segment_length}{Target segment length}
}
\description{
This function "munches" lines, dividing each line into many small pieces
so they can be transformed independently. Used inside geom functions.
}
\keyword{internal}

21 changes: 21 additions & 0 deletions man/graphical-units.Rd
@@ -0,0 +1,21 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/geom-.r
\docType{data}
\name{graphical-units}
\alias{.pt}
\alias{.stroke}
\alias{graphical-units}
\title{Graphical units}
\format{\preformatted{ num 2.83
}}
\usage{
.pt

.stroke
}
\description{
Multiply size in mm by these constants in order to convert to the units
that grid uses internally for \code{lwd} and \code{fontsize}.
}
\keyword{datasets}

29 changes: 29 additions & 0 deletions man/remove_missing.Rd
@@ -0,0 +1,29 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/utilities.r
\name{remove_missing}
\alias{remove_missing}
\title{Convenience function to remove missing values from a data.frame}
\usage{
remove_missing(df, na.rm = FALSE, vars = names(df), name = "",
finite = FALSE)
}
\arguments{
\item{df}{data.frame}

\item{na.rm}{If true, will suppress warning message.}

\item{vars}{Character vector of variables to check for missings in}

\item{name}{Optional function name to improve error message.}

\item{finite}{If \code{TRUE}, will also remove non-finite values.}
}
\description{
Remove all non-complete rows, with a warning if \code{na.rm = FALSE}.
ggplot is somewhat more accommodating of missing values than R generally.
For those stats which require complete data, missing values will be
automatically removed with a warning. If \code{na.rm = TRUE} is supplied
to the statistic, the warning will be suppressed.
}
\keyword{internal}

0 comments on commit 93ab9e0

Please sign in to comment.