[Rd] Missing PROTECT in intern_getwd (in util.c) (PR#13424)

2009-01-03 Thread milbo
Full_Name: Stephen Milborrow
Version: 2.8.1
OS: WinXP
Submission from: (NULL) (198.54.202.150)


There is a missing PROTECT in intern_getwd in util.c. The current code is

  rval = allocVector(STRSXP, 1);
  SET_STRING_ELT(rval, 0, mkCharCE(buf, CE_UTF8));

and should be (because mkCharCE can allocate memory)

  PROTECT(rval = allocVector(STRSXP, 1));
  SET_STRING_ELT(rval, 0, mkCharCE(buf, CE_UTF8));
  UNPROTECT(1);

This was seen in R version 2.8.1 mingw32

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


Re: [Rd] (PR#13424) Missing PROTECT in intern_getwd (in util.c)

2009-01-03 Thread Prof Brian Ripley

On Sat, 3 Jan 2009, mi...@sonic.net wrote:


Full_Name: Stephen Milborrow
Version: 2.8.1
OS: WinXP
Submission from: (NULL) (198.54.202.150)


There is a missing PROTECT in intern_getwd in util.c. The current code is

 rval = allocVector(STRSXP, 1);
 SET_STRING_ELT(rval, 0, mkCharCE(buf, CE_UTF8));

and should be (because mkCharCE can allocate memory)

 PROTECT(rval = allocVector(STRSXP, 1));
 SET_STRING_ELT(rval, 0, mkCharCE(buf, CE_UTF8));
 UNPROTECT(1);

This was seen in R version 2.8.1 mingw32


And it is code specific to that platform (although you did not say so).

Fixed now in R-patched, thank you.

--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


[Rd] bug report: writeForeignSAS in package "foreign" (PR#13423)

2009-01-03 Thread ken_kleinman
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") ||
inherits(x, "dates") || inherits(x, "date"))
xdates <- sapply(df, FUN = function(x) inherits(x, "dates") ||
inherits(x, "date"))
datetimes <- sapply(df, FUN = function(x) inherits(x, "POSIXt"))
varlabels <- names(df)
varnames <- make.SAS.names(names(df), validvarname = validvarname)
if (any(varnames != varlabels))
message("Some variable names were abbreviated or otherwise altered.")
dfn <- df
if (any(factors))
dfn[factors] <- lapply(dfn[factors], as.numeric)write
if (any(datetimes))
dfn[datetimes] <- lapply(dfn[datetimes], function(x) format(x,
"%d%b%Y %H:%M:%S"))
if (any(xdates))
dfn[xdates] <- lapply(dfn[xdates], function(x) as.Date(as.POSIXct(x)))
write.table(dfn, file = datafile, row = FALSE, col = FALSE,
sep = ",", quote = TRUE, na = "")
lrecl <- max(sapply(readLines(datafile), nchar)) + 4L
cat("* Written by R;\n", file = codefile)
cat("* ", deparse(sys.call(-2L))[1L], ";\n\n", file = codefile,
append = TRUE)
if (any(factors)) {
cat("PROC FORMAT;\n", file = codefile, append = TRUE)
fmtnames <- make.SAS.formats(varnames[factors])
fmt.values <- lapply(df[, factors, drop = FALSE], levels)
names(fmt.values) <- fmtnames
for (f in fmtnames) {
cat("value", f, "\n", file = codefile, append = TRUE)
values <- fmt.values[[f]]
for (i in 1L:length(values)) {
cat("", i, "=", adQuote(values[i]), "\n",
  file = codefile, append = TRUE)
}
cat(";\n\n", file = codefile, append = TRUE)
}
}
cat("DATA ", dataname, ";\n", file = codefile, append = TRUE)
if (any(strings)) {
cat("LENGTH", file = codefile, append = TRUE)
lengths <- sapply(df[, strings, drop = FALSE], FUN =
function(x) max(nchar(x)))
names(lengths) <- varnames[strings]
for (v in varnames[strings]) cat("\n", v, "$", lengths[v],
file = codefile, append = TRUE)
cat("\n;\n\n", file = codefile, append = TRUE)
}
if (any(dates)) {
cat("INFORMAT", file = codefile, append = TRUE)
for (v in varnames[dates]) cat("\n", v, file = codefile,
append = TRUE)
cat("\n YYMMDD10.\n;\n\n", file = codefile, append = TRUE)
}
if (any(datetimes)) {
cat("INFORMAT", file = codefile, append = TRUE)
for (v in varnames[datetimes]) cat("\n", v, file = codefile,
append = TRUE)
cat("\n DATETIME18.\n;\n\n", file = codefile, append = TRUE)
}
cat("INFILE ", adQuote(datafile), "\n DSD", "\n LRECL=",
lrecl, ";\n", file = codefile, append = TRUE)
cat("INPUT", file = codefile, append = TRUE)
for (v in 1L:ncol(df)) cat("\n", varnames[v], file = codefile,
append = TRUE)
if (strings[v])
cat(" $ ", file = codefile, append = TRUE)
cat("\n;\n", file = codefile, append = TRUE)
for (v in 1L:ncol(df)) if (varnames[v] != names(varnames)[v])
cat("LABEL ", varnames[v], "=", adQuote(varlabels[v]),
";\n", file = codefile, append = TRUE)
if (any(factors))
for (f in 1L:length(fmtnames)) cat("FORMAT", names(fmtnames)[f],
paste(fmtnames[f], ".", sep = ""), ";\n", file = codefile,
append = TRUE)
if (any(dates))
for (v in varnames[dates]) cat("FORMAT", v, "yymmdd10.;\n",
file = codefile, append = TRUE)
if (any(datetimes))
for (v in varnames[datetimes]) cat("FORMAT", v, "datetime18.;\n",
file = codefile, append = TRUE)
cat("RUN;\n", file = codefile, append = TRUE)
}

-- 
___
Ken Kleinman, ScD
Associate Professor, Department of Ambulatory Care and Prevention
Harvard Medical School and Harvard Pilgrim Health Care
133 Brookline Ave., 6th Floor
Boston, MA 02215
p: 617 509 9935
f: 617 859 8112
https://dacppages.pbwiki.com/Ken%20Kleinman


"The only useful function of a statistician is to make predictions,
and thus to provide a basis for action." - W.E. Deming

"Cleesh Inbox"  - Me

This email is only for the intended recipient and may contain
information that is privileged, confidential or exempt from disclosure
under applicable Federal or State law. Any review, retransmission,
dissemination or other use of  protected health information by other
than the intended recipient is prohibited. If you received this email
in error, please contact the sender and delete the material.

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


Re: [Rd] (PR#13423) bug report: writeForeignSAS in package "foreign"

2009-01-03 Thread Prof Brian Ripley

And did you want to report a bug?

On Fri, 2 Jan 2009, ken_klein...@hms.harvard.edu wrote:


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") ||
   inherits(x, "dates") || inherits(x, "date"))
   xdates <- sapply(df, FUN = function(x) inherits(x, "dates") ||
   inherits(x, "date"))
   datetimes <- sapply(df, FUN = function(x) inherits(x, "POSIXt"))
   varlabels <- names(df)
   varnames <- make.SAS.names(names(df), validvarname = validvarname)
   if (any(varnames != varlabels))
   message("Some variable names were abbreviated or otherwise altered.")
   dfn <- df
   if (any(factors))
   dfn[factors] <- lapply(dfn[factors], as.numeric)write
   if (any(datetimes))
   dfn[datetimes] <- lapply(dfn[datetimes], function(x) format(x,
   "%d%b%Y %H:%M:%S"))
   if (any(xdates))
   dfn[xdates] <- lapply(dfn[xdates], function(x) as.Date(as.POSIXct(x)))
   write.table(dfn, file = datafile, row = FALSE, col = FALSE,
   sep = ",", quote = TRUE, na = "")
   lrecl <- max(sapply(readLines(datafile), nchar)) + 4L
   cat("* Written by R;\n", file = codefile)
   cat("* ", deparse(sys.call(-2L))[1L], ";\n\n", file = codefile,
   append = TRUE)
   if (any(factors)) {
   cat("PROC FORMAT;\n", file = codefile, append = TRUE)
   fmtnames <- make.SAS.formats(varnames[factors])
   fmt.values <- lapply(df[, factors, drop = FALSE], levels)
   names(fmt.values) <- fmtnames
   for (f in fmtnames) {
   cat("value", f, "\n", file = codefile, append = TRUE)
   values <- fmt.values[[f]]
   for (i in 1L:length(values)) {
   cat("", i, "=", adQuote(values[i]), "\n",
 file = codefile, append = TRUE)
   }
   cat(";\n\n", file = codefile, append = TRUE)
   }
   }
   cat("DATA ", dataname, ";\n", file = codefile, append = TRUE)
   if (any(strings)) {
   cat("LENGTH", file = codefile, append = TRUE)
   lengths <- sapply(df[, strings, drop = FALSE], FUN =
function(x) max(nchar(x)))
   names(lengths) <- varnames[strings]
   for (v in varnames[strings]) cat("\n", v, "$", lengths[v],
   file = codefile, append = TRUE)
   cat("\n;\n\n", file = codefile, append = TRUE)
   }
   if (any(dates)) {
   cat("INFORMAT", file = codefile, append = TRUE)
   for (v in varnames[dates]) cat("\n", v, file = codefile,
   append = TRUE)
   cat("\n YYMMDD10.\n;\n\n", file = codefile, append = TRUE)
   }
   if (any(datetimes)) {
   cat("INFORMAT", file = codefile, append = TRUE)
   for (v in varnames[datetimes]) cat("\n", v, file = codefile,
   append = TRUE)
   cat("\n DATETIME18.\n;\n\n", file = codefile, append = TRUE)
   }
   cat("INFILE ", adQuote(datafile), "\n DSD", "\n LRECL=",
   lrecl, ";\n", file = codefile, append = TRUE)
   cat("INPUT", file = codefile, append = TRUE)
   for (v in 1L:ncol(df)) cat("\n", varnames[v], file = codefile,
   append = TRUE)
   if (strings[v])
   cat(" $ ", file = codefile, append = TRUE)
   cat("\n;\n", file = codefile, append = TRUE)
   for (v in 1L:ncol(df)) if (varnames[v] != names(varnames)[v])
   cat("LABEL ", varnames[v], "=", adQuote(varlabels[v]),
   ";\n", file = codefile, append = TRUE)
   if (any(factors))
   for (f in 1L:length(fmtnames)) cat("FORMAT", names(fmtnames)[f],
   paste(fmtnames[f], ".", sep = ""), ";\n", file = codefile,
   append = TRUE)
   if (any(dates))
   for (v in varnames[dates]) cat("FORMAT", v, "yymmdd10.;\n",
   file = codefile, append = TRUE)
   if (any(datetimes))
   for (v in varnames[datetimes]) cat("FORMAT", v, "datetime18.;\n",
   file = codefile, append = TRUE)
   cat("RUN;\n", file = codefile, append = TRUE)
}

--
___
Ken Kleinman, ScD
Associate Professor, Department of Ambulatory Care and Prevention
Harvard Medical School and Harvard Pilgrim Health Care
133 Brookline Ave., 6th Floor
Boston, MA 02215
p: 617 509 9935
f: 617 859 8112
https://dacppages.pbwiki.com/Ken%20Kleinman


"The only useful function of a statistician is to make predictions,
and thus to provide a basis for action." - W.E. Deming

"Cleesh Inbox"  - Me

This email is only for the intended recipient and may contain
information that is privileged, confidential or exempt from disclosure
under applicable Federal or State law. Any review, retransmission,
dissemination or other use of  protected health information by other
than the intended recipient is prohibited. If you received this email
in error, please contact the sender and delete the material.

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



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied 

[Rd] Bug report in foreign library (PR#13425)

2009-01-03 Thread nhorton
here appears to be a bug in the foreign library.  The following code used to
work, but now generates an error when 'package="SAS"' is specified:

ds <- read.csv("http://www.math.smith.edu/sasr/datasets/help.csv";)
# running foreign package version 0.8-30
library(foreign)
# this works fine
write.foreign(ds, "foo", "bar", package="Stata")
# this yields an error
write.foreign(ds, "foo", "bar", package="SAS")
# Error in writeForeignSAS(df = list(id = c(1L, 2L, 3L, 4L, 5L, 6L, 7L,  :
#  object "dfn" not found



There appears to be a space between < and - in foreign:::writeForeignSAS on
or around line 15:

dfn < - df

should be

dfn <- df

<>



--please do not edit the information below--

Version:
 platform = i386-apple-darwin8.11.1
 arch = i386
 os = darwin8.11.1
 system = i386, darwin8.11.1
 status = 
 major = 2
 minor = 8.1
 year = 2008
 month = 12
 day = 22
 svn rev = 47281
 language = R
 version.string = R version 2.8.1 (2008-12-22)

Locale:
en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

Search Path:
 .GlobalEnv, package:foreign, package:stats, package:graphics,
package:grDevices, package:utils, package:datasets, package:methods,
Autoloads, package:base

Nicholas Horton 
Department of Mathematics and Statistics, Smith College
Clark Science Center, Northampton, MA 01063-0001
http://www.math.smith.edu/~nhorton

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


Re: [Rd] Bug report in foreign library (PR#13425)

2009-01-03 Thread Peter Dalgaard

nhor...@email.smith.edu wrote:

here appears to be a bug in the foreign library.  The following code used to
work, but now generates an error when 'package="SAS"' is specified:

ds <- read.csv("http://www.math.smith.edu/sasr/datasets/help.csv";)
# running foreign package version 0.8-30


That's one version ahead of the package in the 2.8.1 source tarball. Did 
you upgrade or is the darwin binary out of sync?



library(foreign)
# this works fine
write.foreign(ds, "foo", "bar", package="Stata")
# this yields an error
write.foreign(ds, "foo", "bar", package="SAS")
# Error in writeForeignSAS(df = list(id = c(1L, 2L, 3L, 4L, 5L, 6L, 7L,  :
#  object "dfn" not found



There appears to be a space between < and - in foreign:::writeForeignSAS on
or around line 15:

dfn < - df

should be

dfn <- df


Yep. That is in 0.8-30 but not in -29...




<>



--please do not edit the information below--

Version:
 platform = i386-apple-darwin8.11.1
 arch = i386
 os = darwin8.11.1
 system = i386, darwin8.11.1
 status = 
 major = 2

 minor = 8.1
 year = 2008
 month = 12
 day = 22
 svn rev = 47281
 language = R
 version.string = R version 2.8.1 (2008-12-22)

Locale:
en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

Search Path:
 .GlobalEnv, package:foreign, package:stats, package:graphics,
package:grDevices, package:utils, package:datasets, package:methods,
Autoloads, package:base

Nicholas Horton 
Department of Mathematics and Statistics, Smith College

Clark Science Center, Northampton, MA 01063-0001
http://www.math.smith.edu/~nhorton

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



--
   O__   Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907

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


[Rd] implementation of NULL in vectors

2009-01-03 Thread Mark Rosen
All,

I was wondering if someone could point me to the location of the code in R
that supports NULL values in vectors. I'm curious as to how you implemented
them.

The only possible solution to me seems that for a double [], you need to
keep a parallel bool [] that tells you whether the value is null or not. The
bool [] doesn't have to be a literal bool [] -- you can keep a bit array.
Things like summing up a vector become complicated -- you need to check if
something is null before you perform an operation on it.

For the purposes of vectors of numeric data types, why not represent NULL as
NaN (as long as you're happy with the standard semantics of NaN)

Thanks.

[[alternative HTML version deleted]]

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


Re: [Rd] implementation of NULL in vectors

2009-01-03 Thread Prof Brian Ripley

On Sat, 3 Jan 2009, Mark Rosen wrote:


All,

I was wondering if someone could point me to the location of the code in R
that supports NULL values in vectors. I'm curious as to how you implemented
them.


We don't allow NULL in atomic vectors. The 'R Internals' manual discusses 
such implementation issues.




The only possible solution to me seems that for a double [], you need to
keep a parallel bool [] that tells you whether the value is null or not. The
bool [] doesn't have to be a literal bool [] -- you can keep a bit array.
Things like summing up a vector become complicated -- you need to check if
something is null before you perform an operation on it.

For the purposes of vectors of numeric data types, why not represent NULL as
NaN (as long as you're happy with the standard semantics of NaN)

Thanks.

[[alternative HTML version deleted]]

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



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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