Bug 17367 - stats::nls does not quote variable names properly
Summary: stats::nls does not quote variable names properly
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Models (show other bugs)
Version: R 3.4.1
Hardware: Other Linux
: P5 enhancement
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2017-12-21 12:45 UTC by Hugo Mildenberger
Modified: 2017-12-29 23:32 UTC (History)
1 user (show)

See Also:


Attachments
Enquote varNames[varIndex] using backticks (669 bytes, patch)
2017-12-21 12:45 UTC, Hugo Mildenberger
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Hugo Mildenberger 2017-12-21 12:45:58 UTC
Created attachment 2310 [details]
Enquote varNames[varIndex] using backticks

This self-contained example demonstrates the problem:

nls(`NO [µmol/l]` ~ a + k*exp(t),start=list(a=0,k=1),
     data=data.frame('NO [µmol/l]'=c(1,3,8,17),t=seq(1:4),check.names=F))


A possible fix involves putting backticks around varNames[varIndex] in nls.R. But there could be a way which avoids to parse the formula after reconstructing it.
Comment 1 Martin Maechler 2017-12-23 18:50:40 UTC
I agree this is a bug.  lm()  does work w/o problem in such a case.

Yes, we should adhere to our own preaching and not use  parse(text=.) I think.

The code in question *does* mention that it is ugly / should be changed.
... I am not really convinced by the patch consequently...
Comment 2 Martin Maechler 2017-12-29 23:32:11 UTC
Fixed today, for now in R-devel 73972 -- planned to port to R-patched "next year".