[R] A bug report?

Ajay Shah ajayshah at mayin.org
Wed Apr 14 04:47:09 CEST 2004


Folks,

I have a strange situation, which I may have isolated as a bug
report. Or, it could just be that there's something about R that I
don't know. :-) I have attached the data file and the program file but
don't know whether these attachments will make it into the list. Here
is my bugreport.R program --

---------------------------------------------------------------------------
buoyancy <- function(year, taxbase, tax, description, plotname) {
  cat("Simple full OLS regression with all data:\n")
  logtax = log(tax)
  logtaxbase = log(taxbase)
  m = lm(logtax ~ logtaxbase)
  summary.lm(m)
  details = summary.lm(m)
}

A <- read.table(file="amodi-data.csv", sep=",", col.names=c("year",
                "gdp.ag", "gdp.mining", "gdp.manuf", "gdp.elecgas",
                "gdp.construction", "gdp.industry", "gdp.services",
                "gdp.fc", "indirect.taxes", "subsidies", "j1",
                "gdp.mp", "gdp.mp.93", "gdp.deflator", "gdp.fc.93",
                "gdp.ag.93", "gdp.industry.93", "gdp.services.93",
                "tax.income", "tax.corporation", "tax.direct.others",
                "tax.direct", "tax.customs", "tax.excise",
                "tax.indirect.others", "tax.indirect", "tax.total"))
A = subset(A, !is.na(A$tax.total))
buoyancy(A$year, A$gdp.mp, A$tax.income, "Personal income tax and GDPmp", "p1")
---------------------------------------------------------------------------

This program does not work. The summary.lm(m) statement seems to have
no effect. When I run it, I get:

$ R --slave < bugreport.R 
Simple full OLS regression with all data:

where it is asif the summary.lm(m) statement never occurred. If I put
in a statement print(m) it works, but the summary.lm(m) does not work.

Now here's what's weird: Suppose I remove the statement that comes
AFTER this summary.lm(m) statement. That is, I don't say
    details = summary.lm(m)
as the last line of the function. In this case, the program works fine!

I'm most confused. I can't see how putting in an assignment statement
AFTER a function call can contaminate a PREVIOUS statement. I would be
most happy if you could guide me...

I am running on a nicely-working notebook which runs Debian linux
kernel 2.4.17, and have R 1.8.1 (2003-11-21). I use the `testing'
branch of Debian.

     -ans.

-- 
Ajay Shah                                                   Consultant
ajayshah at mayin.org                      Department of Economic Affairs
http://www.mayin.org/ajayshah           Ministry of Finance, New Delhi
-------------- next part --------------
buoyancy <- function(year, taxbase, tax, description, plotname) {
  cat("Simple full OLS regression with all data:\n")
  logtax = log(tax)
  logtaxbase = log(taxbase)
  m = lm(logtax ~ logtaxbase)
  summary.lm(m)
  details = summary.lm(m)
}

A <- read.table(file="amodi-data.csv", sep=",", col.names=c("year",
                "gdp.ag", "gdp.mining", "gdp.manuf", "gdp.elecgas",
                "gdp.construction", "gdp.industry", "gdp.services",
                "gdp.fc", "indirect.taxes", "subsidies", "j1",
                "gdp.mp", "gdp.mp.93", "gdp.deflator", "gdp.fc.93",
                "gdp.ag.93", "gdp.industry.93", "gdp.services.93",
                "tax.income", "tax.corporation", "tax.direct.others",
                "tax.direct", "tax.customs", "tax.excise",
                "tax.indirect.others", "tax.indirect", "tax.total"))
A = subset(A, !is.na(A$tax.total))

buoyancy(A$year, A$gdp.mp, A$tax.income, "Personal income tax and GDPmp",
         "p1")


More information about the R-help mailing list