[Rd] typo in reshape.Rd

2007-02-28 Thread Stephen D. Weigand
The 3 lines below are from paragraph 4 of \details in reshape.Rd.
In line [2], a space is needed before "where" and the "to" at the
end of the line should be removed.

[1]these names.  The default is variable names like \code{x.1},
[2]\code{x.2},where \code{split=list(regexp="\\.",include=FALSE)} to
[3]specifies to split at the dot and drop it from the name. To have 
alphabetic

Thanks,

Stephen


Stephen Weigand
Rochester, Minnesota, USA

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Typos in writeLines.Rd, readLines.Rd, and data.matrix.Rd

2006-02-27 Thread Stephen D. Weigand
Hello,

The diffs below are based on revision 37445 and show
some typo corrections for writeLines.Rd, readLines.Rd,
and data.matrix.Rd that I'd like to bring to the list's
attention.

Sincerely,

Stephen Weigand
Rochester, Minnesota, USA



--- ./src/library/base/man/writeLines.RdSun Feb 26 13:46:06 2006
+++ /tmp/writeLines.Rd  Sun Feb 26 20:53:44 2006
@@ -14,8 +14,8 @@
  each line of text.}
  }
  \details{
-  If the \code{con} is a character string, the functions call
-  \code{\link{file}} to obtain an file connection which is opened for
+  If the \code{con} is a character string, the function calls
+  \code{\link{file}} to obtain a file connection which is opened for
the duration of the function call.

If the connection is open it is written from its current position.


--- ./src/library/base/man/readLines.Rd Sun Feb 26 13:46:28 2006
+++ /tmp/readLines.Rd   Sun Feb 26 21:08:30 2006
@@ -16,8 +16,8 @@
  \code{n > 0} lines are read? If not, an error will be generated.}
  }
  \details{
-  If the \code{con} is a character string, the functions call
-  \code{\link{file}} to obtain an file connection which is opened for
+  If the \code{con} is a character string, the function calls
+  \code{\link{file}} to obtain a file connection which is opened for
the duration of the function call.

If the connection is open it is read from its current position.


--- ./src/library/base/man/data.matrix.Rd   Sun Feb 26 13:46:15 2006
+++ /tmp/data.matrix.Rd Sun Feb 26 21:14:33 2006
@@ -15,7 +15,7 @@
  factors or numeric vectors.}
  }
  \details{
-  Suppling a data frame with columns which are not numeric, factor or 
logical
+  Supplying a data frame with columns which are not numeric, factor or 
logical
is an error.  A warning is given if any non-factor column has a 
class,
as then information can be lost.
  }

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Wishlist: 'append' argument for write.ftable()

2006-03-16 Thread Stephen D. Weigand

I would like to suggest that an 'append' argument be added to
write.ftable().  This would allow, for example, the user to
append ftable() output to a text report.

I have attached an svn patch to ftable.R that makes the proposed
change to write.ftable(). [A very trivial change since 'append'
is simply passed to cat().]

I have also attached a patch to read.ftable.Rd which documents
the proposed argument (borrowing from cat.Rd).

Thanks for considering this,

Stephen
--

Stephen Weigand
Rochester, Minnesota, USA__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Wishlist: 'append' argument for write.ftable()

2006-03-16 Thread Stephen D. Weigand


On Mar 16, 2006, at 9:48 PM, Stephen D. Weigand wrote:


I would like to suggest that an 'append' argument be added to
write.ftable().  This would allow, for example, the user to
append ftable() output to a text report.

I have attached an svn patch to ftable.R that makes the proposed
change to write.ftable(). [A very trivial change since 'append'
is simply passed to cat().]

I have also attached a patch to read.ftable.Rd which documents
the proposed argument (borrowing from cat.Rd).


The text-based patch files were attached but had extensions *.patch.
I'm resending them with *.txt extensions in case that's necessary.
Index: R/src/library/stats/R/ftable.R
===
--- R/src/library/stats/R/ftable.R  (revision 37549)
+++ R/src/library/stats/R/ftable.R  (working copy)
@@ -151,7 +151,7 @@
 x
 }
 
-write.ftable <- function(x, file = "", quote = TRUE,
+write.ftable <- function(x, file = "", append = FALSE, quote = TRUE,
  digits = getOption("digits"))
 {
 if(!inherits(x, "ftable"))
@@ -191,7 +191,8 @@
   format(unclass(x), digits = digits))
 x <- cbind(apply(LABS, 2, format, justify = "left"),
apply(DATA, 2, format, justify = "right"))
-cat(t(x), file = file, sep = c(rep(" ", ncol(x) - 1), "\n"))
+cat(t(x), file = file, append = append,
+sep = c(rep(" ", ncol(x) - 1), "\n"))
 invisible(ox)
 }
 
Index: R/src/library/stats/man/read.ftable.Rd
===
--- R/src/library/stats/man/read.ftable.Rd  (revision 37549)
+++ R/src/library/stats/man/read.ftable.Rd  (working copy)
@@ -31,6 +31,10 @@
   \item{skip}{the number of lines of the data file to skip before
 beginning to read data.}
   \item{x}{an object of class \code{"ftable"}.}
+  \item{append}{logical.  If \code{TRUE} and \code{file} is the name of
+a file (and not a connection or \code{"|cmd"}), the output from
+\code{write.ftable} is appended to the file.  If \code{FALSE},
+the contents of \code{file} will be overwritten.}
   \item{digits}{an integer giving the number of significant digits to
 use for (the cell entries of) \code{x}.}
   \item{\dots}{further arguments to be passed to or from methods.}


As a backup, the patches are in-line below.
Thanks again,
Stephen


Index: R/src/library/stats/R/ftable.R
===
--- R/src/library/stats/R/ftable.R  (revision 37549)
+++ R/src/library/stats/R/ftable.R  (working copy)
@@ -151,7 +151,7 @@
 x
 }

-write.ftable <- function(x, file = "", quote = TRUE,
+write.ftable <- function(x, file = "", append = FALSE, quote = TRUE,
  digits = getOption("digits"))
 {
 if(!inherits(x, "ftable"))
@@ -191,7 +191,8 @@
   format(unclass(x), digits = digits))
 x <- cbind(apply(LABS, 2, format, justify = "left"),
apply(DATA, 2, format, justify = "right"))
-cat(t(x), file = file, sep = c(rep(" ", ncol(x) - 1), "\n"))
+cat(t(x), file = file, append = append,
+sep = c(rep(" ", ncol(x) - 1), "\n"))
 invisible(ox)
 }

Index: R/src/library/stats/man/read.ftable.Rd
===
--- R/src/library/stats/man/read.ftable.Rd  (revision 37549)
+++ R/src/library/stats/man/read.ftable.Rd  (working copy)
@@ -31,6 +31,10 @@
   \item{skip}{the number of lines of the data file to skip before
 beginning to read data.}
   \item{x}{an object of class \code{"ftable"}.}
+  \item{append}{logical.  If \code{TRUE} and \code{file} is the name of
+a file (and not a connection or \code{"|cmd"}), the output from
+\code{write.ftable} is appended to the file.  If \code{FALSE},
+the contents of \code{file} will be overwritten.}
   \item{digits}{an integer giving the number of significant digits to
 use for (the cell entries of) \code{x}.}
   \item{\dots}{further arguments to be passed to or from methods.}
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] writeForeignSAS and potential extensions

2006-07-13 Thread Stephen D. Weigand
Sorry, looks like my work e-mailer put the attachments
in the body. Please e-mail [EMAIL PROTECTED] if interested
and I'll send you a copy of the files.

I think it'll also work to grab the files from:

ftp://mayoftp:''@ftp.mayo.edu/pub/weigand/writeForeignSAS7.R
ftp://mayoftp:''@ftp.mayo.edu/pub/weigand/diff.txt

Thank you,
Stephen

On Jul 13, 2006, at 1:48 PM, Stephen Weigand wrote:

> Dear R-devel,
>
> I've made some potential extensions to writeForeignSAS
> in 'foreign' that I wanted to pass along if anyone is
> interested.  I've attached the diff -u output against
> the version found in foreign_0.8-15 and an .R file
> with my changes.  (In this .R file, the function is named
> writeForeignSAS7 to simplify testing/comparisons.)
>
> I've tried to alter the current version as little as
> possible while making the following changes:
>
> * Try to convert data.frame names to SAS-legal names and
> allow the user to specify an 8- or 32-character limit.
>
> * For factors, try to convert the variable name to a
> SAS-legal 8-character name not ending in a digit
>
> * Read in 'datafile' with DSD specified in the INFILE
> statement.  SAS says this "changes how SAS treats
> delimiters when list input is used and sets the default
> delimiter to a comma.  When you specify DSD, SAS treats
> two consecutive delimiters as a missing value and
> removes quotation marks from character values."  The
> point of this is the added safety of using 'quote=TRUE'
> when writing 'datafile' via write.table
>
> * Functionality to write out Dates and read them in with
> an INFORMAT statement
>
> * Functionality to write out datetime variables
> (assuming a class of POSIXct) and read them in with an
> INFORMAT statement
>
> * In order to handle character variables a bit better,
> use a LENGTH statement to tell SAS the maximum character
> width of values in the variable. Without this, some
> character values can be truncated.
>
> If it'd be helpful to make any changes or add anything,
> I'd be happy try to do so.
>
> Finally, some testing code that works in SAS 6.12, 8.2,
> and 9.
>
> d <-
>   structure(list(a.b = as.integer(c(1, 2)),
>  alphabetsoup =
>  structure(as.integer(c(1, 2)),
>.Label = c("A", "B"),
>class = "factor"),
>  datevar1 = structure(c(13342, 12977),
>   class = "Date"),
>  datetimevar1 = structure(c(1152802685,
> 1152716285),
>class = c("POSIXt", "POSIXct")),
>  charactervariable = c("L",
> "Last, First")),
> .Names = c("a.b", "alphabetsoup",
> "datevar1", "datetimevar1",
> "charactervariable"),
> row.names = c("1", "2"),
> class = "data.frame")
>
> require(foreign)
>
> ### adQuote here to (temporarily) avoid ':::'
> adQuote <- function (x) paste("\"", x, "\"", sep = "")
>
> dfile <- file.path(tempdir(), "test.dat")
> cfile <- file.path(tempdir(), "test.sas")
> write.foreign(d, datafile = dfile, codefile = cfile,
>   package = "SAS7", validvarname = "V6")
> file.show(dfile)
> file.show(cfile)
>
> Sincerely,
>
> Stephen
>
> ::
> Stephen Weigand
> Division of Biostatistics
> Mayo Clinic Rochester, Minn., USA
> Phone (507) 266-1650, fax 284-9542
> --- writeForeignSAS.R Fri Feb 17 03:30:53 2006
> +++ /tmp/writeForeignSAS.RThu Jul 13 12:24:24 2006
> @@ -1,21 +1,52 @@
> -writeForeignSAS<-function(df,datafile,codefile,dataname="rdata"){
> +make.SAS.names <- function(varnames, validvarname = c("V7", "V6")){
> +  validvarname <- match.arg(validvarname)
> +  nmax <- if(validvarname == "V7") 32 else 8
>
> +  x <- sub("^([0-9])", "_\\1", varnames)
> +  x <- gsub("[^a-zA-Z0-9_]", "_", x)
> +  x <- abbreviate(x, minlength = nmax)
> +
> +  if (any(nchar(x) > nmax) || any(duplicated(x)))
> +stop("Cannot uniquely abbreviate the variable names to ",
> + nmax, " or fewer characters")
> +  names(x) <- varnames
> +  x
> +}
> +
> +make.SAS.formats <- function(varnames){
> +  x <- sub("^([0-9])", "_\\1", varnames)
> +  x <- gsub("[^a-zA-Z0-9_]", "_", x)
> +  x <- sub("([0-9])$", "\\1f", x) # can't end in digit so append 'f'
> +  x <- abbreviate(x, minlength = 8)
> +
> +  if(any(nchar(x) > 8) || any(duplicated(x)))
> +stop("Cannot uniquely abbreviate format names to conform to ",
> + " eight-character limit and not ending in a digit")
> +  names(x) <- varnames
> +  x
> +}
> +
> +writeForeignSAS7<-function(df,datafile,codefile,dataname="rdata",
> +  validvarname = c("V7", "V6")){
>factors <- sapply(df, is.factor)
>strings <- sapply(df, is.character)
> -
> +  dates <- sapply(df, FUN = function(x) inherits(x, "Date"))
> +  datetimes <- sapply(df, FUN = function(x) inherits(x, "POSIXct"))
> +
>varlabels <- names(df)
> -  varnames <- abbr

[Rd] Wishlist: abs method for difftime

2006-12-07 Thread Stephen D. Weigand
I am often taking the absolute value of a difftime object (after
coercing it to numeric) in order to see how far apart in time
two events are. For example, I might want to know if two events
occurred within 100 days of each other using something like

abs(difftime(Date1, Date2)) < 100

Below is a suggestion for an abs.difftime:

abs.difftime <- function(x)
{
 structure(abs(as.numeric(x)),
   class = class(x),
   units = attr(x, "units"))
}

I think these changes to difftime.Rd would document this:

1) Add \alias{abs.difftime}

2) In the first paragraph of \details change

"There is a \code{\link{round}} method for objects of this class,
as well as..."

to

"There are \code{\link{round}} and \code{\link{abs}} methods for
objects of this class, as well as..."

Thanks for considering this,

Stephen
Rochester, Minnesota, USA

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel