[Roxygen-commits] r180 - in pkg: R inst/doc sandbox

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Aug 25 06:08:25 CEST 2008


Author: pcd
Date: 2008-08-25 06:08:25 +0200 (Mon, 25 Aug 2008)
New Revision: 180

Added:
   pkg/inst/doc/hello-roxygen.R
   pkg/inst/doc/pseudoprime.R
Removed:
   pkg/inst/doc/example-pseudoprime.R
Modified:
   pkg/R/roxygenize.R
   pkg/inst/doc/roxygen.Rnw
   pkg/sandbox/example-pseudoprime.R
Log:
clarify roxygen.dir's default; listing command; abstract; minimal example; is.fermat.prime -> is.pseudoprime


Modified: pkg/R/roxygenize.R
===================================================================
--- pkg/R/roxygenize.R	2008-08-24 08:37:19 UTC (rev 179)
+++ pkg/R/roxygenize.R	2008-08-25 04:08:25 UTC (rev 180)
@@ -61,7 +61,8 @@
 
 #' Process a package with the Rd, namespace and collate roclets.
 #' @param package.dir the package's top directory
-#' @param roxygen.dir whither to copy roxygen files
+#' @param roxygen.dir whither to copy roxygen files; defaults to
+#' \file{package.roxygen}.
 #' @param copy.package copies the package over before
 #' adding/manipulating files.
 #' @param overwrite overwrite target files

Deleted: pkg/inst/doc/example-pseudoprime.R
===================================================================
--- pkg/inst/doc/example-pseudoprime.R	2008-08-24 08:37:19 UTC (rev 179)
+++ pkg/inst/doc/example-pseudoprime.R	2008-08-25 04:08:25 UTC (rev 180)
@@ -1 +0,0 @@
-link ../../sandbox/example-pseudoprime.R
\ No newline at end of file

Added: pkg/inst/doc/hello-roxygen.R
===================================================================
--- pkg/inst/doc/hello-roxygen.R	                        (rev 0)
+++ pkg/inst/doc/hello-roxygen.R	2008-08-25 04:08:25 UTC (rev 180)
@@ -0,0 +1,3 @@
+#' @name helloRoxygen-package
+#' @docType package
+roxygen()

Copied: pkg/inst/doc/pseudoprime.R (from rev 179, pkg/sandbox/example-pseudoprime.R)
===================================================================
--- pkg/inst/doc/pseudoprime.R	                        (rev 0)
+++ pkg/inst/doc/pseudoprime.R	2008-08-25 04:08:25 UTC (rev 180)
@@ -0,0 +1,43 @@
+#' Test an integer for primality with Fermat's Little Theorem.
+#'
+#' Fermat's Little Theorem states that if \eqn{n} is a prime
+#' number and \eqn{a} is any positive integer less than \eqn{n},
+#' then \eqn{a} raised to the \eqn{n}th power is congruent to
+#' \eqn{a modulo n}.
+#'
+#' @author Peter Danenberg \email{pcd@@roxygen.org}
+#' @param n the integer to test for primality
+#' @return Whether the integer passes the Fermat test
+#'   for a randomized \eqn{0 < a < n}
+#' @note \code{fermat.test} doesn't work for integers above
+#'   approximately fifteen because modulus loses precision.
+fermat.test <- function(n) {
+  a <- floor(runif(1, min=1, max=n))
+  a ^ n %% n == a
+}
+
+#' Check an integer for pseudo-primality to an arbitrary
+#' precision.
+#'
+#' A number is pseudo-prime if it is probably prime, the basis
+#' of which is the probabilistic Fermat test; if it passes two
+#' such tests, the chances are better than 3 out of 4 that
+#' \eqn{n} is prime.
+#'
+#' @author Peter Danenberg \email{pcd@@roxygen.org}
+#' @param n the integer to test for pseudoprimality.
+#' @param times the number of Fermat tests to perform
+#' @return Whether the number is pseudoprime
+#' @export
+#' @seealso \code{\link{fermat.test}}
+#' @references Abelson, Hal; Jerry Sussman, and Julie Sussman.
+#'   Structure and Interpretation of Computer Programs.
+#'   Cambridge: MIT Press, 1984.
+#' @keywords pseudoprime fermat
+#' @examples
+#' is.pseudoprime(13, 4)  # TRUE most of the time
+is.pseudoprime <- function(n, times) {
+  if (times == 0) TRUE
+  else if (fermat.test(n)) is.pseudoprime(n, times - 1)
+  else FALSE
+}

Modified: pkg/inst/doc/roxygen.Rnw
===================================================================
--- pkg/inst/doc/roxygen.Rnw	2008-08-24 08:37:19 UTC (rev 179)
+++ pkg/inst/doc/roxygen.Rnw	2008-08-25 04:08:25 UTC (rev 180)
@@ -1,9 +1,54 @@
 \documentclass{article}
 \usepackage{fancyvrb}
+\usepackage{url}
+\newcommand{\Roxygen}{\texttt{Roxygen}}
+%% filename, caption, label
+\newcommand{\listing}[3]{        %
+  \begin{figure}                 %
+    \centering                   %
+    \VerbatimInput[numbers=left, %
+      frame=single,              %
+      label=#1]{#1}              %
+    \caption{#2}                 %
+    \label{#3}                   %
+  \end{figure}                   %
+}
+\author{Peter Danenberg \url{<pcd at roxygen.org>}}
+\title{\Roxygen{} Vignette}
 \begin{document}
-\begin{figure}
-  \centering
-  \VerbatimInput[numbers=left, frame=single]{example-pseudoprime.R}
-  \caption{Roxygen example \texttt{example-pseudoprime.R}}
-\end{figure}
+\maketitle
+\begin{abstract}
+  The purpose of the \Roxygen{} Vignette is to show how to get up and
+  running with \Roxygen{}; for details, including a complete list of
+  tags, consult the help pages for:
+  \begin{itemize}
+  \item \texttt{make.callgraph.roclet}
+  \item \texttt{make.collate.roclet}
+  \item \texttt{make.namespace.roclet}
+  \item \texttt{make.Rd.roclet}
+  \end{itemize}
+\end{abstract}
+\tableofcontents
+\section{Minimal example}
+
+\listing{hello-roxygen.R}
+        {Roxygen sanity-check \texttt{hello-roxygen.R}}
+        {hello-roxygen}
+
+A minimal example that serves as a sanity check is found in
+\texttt{hello-roxygen.R} (see Figure \ref{hello-roxygen}). It merely
+replaces the package description so that \texttt{R CMD check} will run
+after \Roxygen{} has processed the package skeleton:
+
+<<results=hide, keep.source=true>>=
+library(roxygen)
+package.skeleton('helloRoxygen',
+                 code_files='hello-roxygen.R',
+                 force=TRUE)
+# `R CMD roxygen helloRoxygen' works, too.
+roxygenize('helloRoxygen')
+@
+\listing{pseudoprime.R}
+        {Roxygen example \texttt{pseudoprime.R}}
+        {pseudoprime}
 \end{document}

Modified: pkg/sandbox/example-pseudoprime.R
===================================================================
--- pkg/sandbox/example-pseudoprime.R	2008-08-24 08:37:19 UTC (rev 179)
+++ pkg/sandbox/example-pseudoprime.R	2008-08-25 04:08:25 UTC (rev 180)
@@ -9,6 +9,8 @@
 #' @param n the integer to test for primality
 #' @return Whether the integer passes the Fermat test
 #'   for a randomized \eqn{0 < a < n}
+#' @note \code{fermat.test} doesn't work for integers above
+#'   approximately fifteen because modulus loses precision.
 fermat.test <- function(n) {
   a <- floor(runif(1, min=1, max=n))
   a ^ n %% n == a
@@ -36,6 +38,6 @@
 #' is.pseudoprime(13, 4)  # TRUE most of the time
 is.pseudoprime <- function(n, times) {
   if (times == 0) TRUE
-  else if (fermat.test(n)) is.fermat.prime(n, times - 1)
+  else if (fermat.test(n)) is.pseudoprime(n, times - 1)
   else FALSE
 }



More information about the Roxygen-commits mailing list