[Rd] illegal data frame produced by [<-.data.frame (PR#10574)

timh at insightful.com timh at insightful.com
Mon Jan 14 19:40:08 CET 2008


> x <- data.frame(a=1:3,b=2:4)
> x[,3] <- x
Warning message:
In `[<-.data.frame`(`*tmp*`, , 3, value = list(a = 1:3, b = 2:4)) :
  provided 2 variables to replace 1 variables
> x
  a b a.1  b.1
1 1 2   1 NULL
2 2 3   2 <NA>
3 3 4   3 <NA>
Warning message:
In format.data.frame(x, digits = digits, na.encode = FALSE) :
  corrupt data frame: columns will be truncated or padded with NAs

In S-PLUS, the first warning is given, then a legal data frame
is produced, using only the first column of value.
The following change to R's "[<-.data.frame" gives that behavior.
Change:

    else if (ncolv > p) 
        warning(gettextf("provided %d variables to replace %d variables", 
            ncolv, p), domain = NA)

to:

    else if (ncolv > p) {
        warning(gettextf("provided %d variables to replace %d variables", 
            ncolv, p), domain = NA)
        new.cols <- new.cols[seq_len(p)]
    }






--please do not edit the information below--

Version:
 platform = i386-pc-mingw32
 arch = i386
 os = mingw32
 system = i386, mingw32
 status = 
 major = 2
 minor = 6.1
 year = 2007
 month = 11
 day = 26
 svn rev = 43537
 language = R
 version.string = R version 2.6.1 (2007-11-26)

Windows XP (build 2600) Service Pack 2.0

Locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

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



More information about the R-devel mailing list