Full_Name: Travis Porco Version: 1.5.1 (6/17/2002) OS: Suse Linux 7.1 Submission from: (NULL) (66.81.124.235) This happens:> integrate(function(x)1,0,1)Error in integrate(function(x) 1, 0, 1) : evaluation of function gave a result of wrong length> integrate(function(x)x^2,0,1)0.3333333 with absolute error < 3.7e-15> integrate(function(x){cat(x);1},0,1)0.5 0.01304674 0.9869533 0.06746832 0.9325317 0.1602952 0.8397048 0.2833023 0.7166977 0.4255628 0.5744372 0.002171418 0.9978286 0.03492125 0.9650787 0.1095911 0.8904089 0.2186214 0.7813786 0.3528036 0.6471964Error in integrate(function(x){ : evaluation of function gave a result of wrong length This is clearly incorrect behavior. I included case 2 to show that some cases are working correctly. Various other conditions produce the error message indicated. Of course, not being able to integrate a constant is not in itself the problem; rather, function(x)1 generates the same error that occurs in the real problem I'm working on. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
There is no bug. The error message tells you that your function gives a result of the wrong length - that means your function should give a result with length the same as that of the input argument, x. Try either of the following> integrate(function(x) 1 + 0*x, 0, 1) > integrate(function(x) rep(1, length(x)), 0, 1)If you spot the message in these it could be the start of a seminal lesson on vectorization. Bill Venables -----Original Message----- From: tcporco@mathepi.com [mailto:tcporco@mathepi.com] Sent: Monday, July 08, 2002 10:33 AM To: r-devel@stat.math.ethz.ch Cc: R-bugs@biostat.ku.dk Subject: integrate() (PR#1755) Full_Name: Travis Porco Version: 1.5.1 (6/17/2002) OS: Suse Linux 7.1 Submission from: (NULL) (66.81.124.235) This happens:> integrate(function(x)1,0,1)Error in integrate(function(x) 1, 0, 1) : evaluation of function gave a result of wrong length> integrate(function(x)x^2,0,1)0.3333333 with absolute error < 3.7e-15> integrate(function(x){cat(x);1},0,1)0.5 0.01304674 0.9869533 0.06746832 0.9325317 0.1602952 0.8397048 0.2833023 0.7166977 0.4255628 0.5744372 0.002171418 0.9978286 0.03492125 0.9650787 0.1095911 0.8904089 0.2186214 0.7813786 0.3528036 0.6471964Error in integrate(function(x){ : evaluation of function gave a result of wrong length This is clearly incorrect behavior. I included case 2 to show that some cases are working correctly. Various other conditions produce the error message indicated. Of course, not being able to integrate a constant is not in itself the problem; rather, function(x)1 generates the same error that occurs in the real problem I'm working on. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I think people should read the documentation more carefully before sending e-mail to R-bugs to make sure that they understand their problem correctly. If in doubt, the problem should be reported to the R-help list. I do not think there is anything wrong with integrate. Here is a relevant excerpt from the man page:> f: An R function taking a numeric first argument and returning a > numeric vector the same length. Returning a non-finite > element will generate an error.This simply means that the function has to be properly vectorized. Your first example - the constant function - is not. If you replaced it with something like integrate(function(x) rep(1, length(x)), 0, 1) integrate would work properly. Your second function works correctly since x^2 returns a vector result of the same length as x. The last one is really strange. I think integrate should return an error message in this case. Andy __________________________________ Andy Jaworski Engineering Systems Technology Center 3M Center, 518-1-01 St. Paul, MN 55144-1000 ----- E-mail: apjaworski@mmm.com Tel: (651) 733-6092 Fax: (651) 736-3122 |---------+-----------------------------> | | tcporco@mathepi.co| | | m | | | | | | 07/07/2002 19:32 | | | | |---------+-----------------------------> >-----------------------------------------------------------------------------------------------------------------------------| | | | To: r-devel@stat.math.ethz.ch | | cc: R-bugs@biostat.ku.dk | | (bcc: Andrzej P. Jaworski/US-Corporate/3M/US) | | Subject: integrate() (PR#1755) | >-----------------------------------------------------------------------------------------------------------------------------| Full_Name: Travis Porco Version: 1.5.1 (6/17/2002) OS: Suse Linux 7.1 Submission from: (NULL) (66.81.124.235) This happens:> integrate(function(x)1,0,1)Error in integrate(function(x) 1, 0, 1) : evaluation of function gave a result of wrong length> integrate(function(x)x^2,0,1)0.3333333 with absolute error < 3.7e-15> integrate(function(x){cat(x);1},0,1)0.5 0.01304674 0.9869533 0.06746832 0.9325317 0.1602952 0.8397048 0.2833023 0.7166977 0.4255628 0.5744372 0.002171418 0.9978286 0.03492125 0.9650787 0.1095911 0.8904089 0.2186214 0.7813786 0.3528036 0.6471964Error in integrate(function(x){ : evaluation of function gave a result of wrong length This is clearly incorrect behavior. I included case 2 to show that some cases are working correctly. Various other conditions produce the error message indicated. Of course, not being able to integrate a constant is not in itself the problem; rather, function(x)1 generates the same error that occurs in the real problem I'm working on. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Thanks much. I downloaded the source and see the problem. I misinterpreted the manual as meaning that any function that took a single argument and returned a single argument would be fine, when the manual and the error message were trying to tell me that the function should simply be vectorized. Obvious in retrospect. Sorry to have bothered you about it. kind regards, -travis porco -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._