Bug 16436 - model.frame.default() can change objects external to the function
Summary: model.frame.default() can change objects external to the function
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Models (show other bugs)
Version: R 3.2.0
Hardware: Other Other
: P5 enhancement
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2015-06-20 20:14 UTC by J. R. M. Hosking
Modified: 2015-12-14 13:48 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description J. R. M. Hosking 2015-06-20 20:14:59 UTC
model.frame.default() with certain values of 'na.action' can change objects external to the function -- specifically, the "class" attribute of a multivariate time series object that appears in the 'formula' argument of model.frame().

  class(EuStockMarkets)  # "mts"    "ts"     "matrix"
  mf <- model.frame(EuStockMarkets ~ 1, na.action=na.fail)
  class(EuStockMarkets)  # 
"mts"    "matrix"

Line-by-line debugging of model.frame.default() indicates that the change in the attribute value occurs inside the call                                 
                                                                          
  data <- .External2(C_modelframe, formula, rownames, variables,          
          varnames, extras, extranames, subset, na.action)                

So possibly there is some memory management issue within C_modelframe -- I haven't pursued it further.


> sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base 



J. R. M. Hosking
Comment 1 Duncan Murdoch 2015-06-21 11:41:14 UTC
I can confirm this; I'll see if I can spot where it happens.
Comment 2 Duncan Murdoch 2015-06-21 12:41:03 UTC
Fixed in R-devel and R-patched as of rev 68565.  The problem was that subsetting could mess with the time series characteristics, so the ts attributes were removed; but in this case, no change had happened, so the removal was done to the original data.