knittr is giving me the above error. The code it is failing on is multiplying two numeric features of a data frame. I can run the code by hand and it works fine, but when I try to knit my document, knittr chokes on the same line. When kitting: Quitting from lines 161-175 (RepData_PeerAssessment2.Rmd) Error in storm_data$PROPDMG * storm_data$property_damage_cost_factor : non-numeric argument to binary operator Calls: <Anonymous> ... handle -> withCallingHandlers -> withVisible -> eval -> eval Execution halted Running the same lines manually (CTRL+Enter) from the .Rmd file:> storm_data$total_damage <-+ (storm_data$PROPDMG * storm_data$property_damage_cost_factor) + + (storm_data$CROPDMG * storm_data$crop_damage_cost_factor)> str(storm_data$total_damage)num [1:902297] 25 2.5 25 2.5 2.5 2.5 2.5 2.5 25 25 ...>Call me baffled. Any pointers are greatly appreciated at this point. -- Cheers, Mark Mark Drummond mark at markdrummond.ca When I get sad, I stop being sad and be Awesome instead. TRUE STORY.
Not reproducible [1], so any response likely to be a guess. However, you likely have not put everything that is in your interactive environment into the knitr document, so you are not working with the same data in those two environments. [1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. On April 26, 2015 1:41:32 PM PDT, Mark Drummond <mark at markdrummond.ca> wrote:>knittr is giving me the above error. The code it is failing on is >multiplying two numeric features of a data frame. I can run the code >by hand and it works fine, but when I try to knit my document, knittr >chokes on the same line. > >When kitting: > >Quitting from lines 161-175 (RepData_PeerAssessment2.Rmd) >Error in storm_data$PROPDMG * storm_data$property_damage_cost_factor : > non-numeric argument to binary operator >Calls: <Anonymous> ... handle -> withCallingHandlers -> withVisible -> >eval -> eval >Execution halted > >Running the same lines manually (CTRL+Enter) from the .Rmd file: > >> storm_data$total_damage <- >+ (storm_data$PROPDMG * storm_data$property_damage_cost_factor) + >+ (storm_data$CROPDMG * storm_data$crop_damage_cost_factor) >> str(storm_data$total_damage) > num [1:902297] 25 2.5 25 2.5 2.5 2.5 2.5 2.5 25 25 ... >> > >Call me baffled. Any pointers are greatly appreciated at this point.
We need some idea of what you were actually doing (i.e code, data, ... ) See http://adv-r.had.co.nz/Reproducibility.html for some suggestions. John Kane Kingston ON Canada> -----Original Message----- > From: mark at markdrummond.ca > Sent: Sun, 26 Apr 2015 16:41:32 -0400 > To: r-help at stat.math.ethz.ch > Subject: [R] knittr: non-numeric argument to binary operator > > knittr is giving me the above error. The code it is failing on is > multiplying two numeric features of a data frame. I can run the code > by hand and it works fine, but when I try to knit my document, knittr > chokes on the same line. > > When kitting: > > Quitting from lines 161-175 (RepData_PeerAssessment2.Rmd) > Error in storm_data$PROPDMG * storm_data$property_damage_cost_factor : > non-numeric argument to binary operator > Calls: <Anonymous> ... handle -> withCallingHandlers -> withVisible -> > eval -> eval > Execution halted > > Running the same lines manually (CTRL+Enter) from the .Rmd file: > >> storm_data$total_damage <- > + (storm_data$PROPDMG * storm_data$property_damage_cost_factor) + > + (storm_data$CROPDMG * storm_data$crop_damage_cost_factor) >> str(storm_data$total_damage) > num [1:902297] 25 2.5 25 2.5 2.5 2.5 2.5 2.5 25 25 ... >> > > Call me baffled. Any pointers are greatly appreciated at this point. > > -- > Cheers, Mark > > Mark Drummond > mark at markdrummond.ca > > When I get sad, I stop being sad and be Awesome instead. TRUE STORY. > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.____________________________________________________________ Can't remember your password? Do you need a strong and secure password? Use Password manager! It stores your passwords & protects your account.
I was getting pretty much the same error recently, when I joined this list (I'm new to R), and the solution turned out to be that I needed to call as.integer() on a certain value, before passing it to a function. In my case it was a value read/returned from commandArgs(), but I suppose there are other situations where this could arise. Milt Epstein Programmer in Computational Genomics Institute for Genomic Biology (IGB) University of Illinois at Urbana-Champaign (UIUC) mepstein at illinois.edu On Sun, 26 Apr 2015, John Kane wrote:> We need some idea of what you were actually doing (i.e code, data, ... ) > > See http://adv-r.had.co.nz/Reproducibility.html for some suggestions. > John Kane > Kingston ON Canada > > > > -----Original Message----- > > From: mark at markdrummond.ca > > Sent: Sun, 26 Apr 2015 16:41:32 -0400 > > To: r-help at stat.math.ethz.ch > > Subject: [R] knittr: non-numeric argument to binary operator > > > > knittr is giving me the above error. The code it is failing on is > > multiplying two numeric features of a data frame. I can run the code > > by hand and it works fine, but when I try to knit my document, knittr > > chokes on the same line. > > > > When kitting: > > > > Quitting from lines 161-175 (RepData_PeerAssessment2.Rmd) > > Error in storm_data$PROPDMG * storm_data$property_damage_cost_factor : > > non-numeric argument to binary operator > > Calls: <Anonymous> ... handle -> withCallingHandlers -> withVisible -> > > eval -> eval > > Execution halted > > > > Running the same lines manually (CTRL+Enter) from the .Rmd file: > > > >> storm_data$total_damage <- > > + (storm_data$PROPDMG * storm_data$property_damage_cost_factor) + > > + (storm_data$CROPDMG * storm_data$crop_damage_cost_factor) > >> str(storm_data$total_damage) > > num [1:902297] 25 2.5 25 2.5 2.5 2.5 2.5 2.5 25 25 ... > >> > > > > Call me baffled. Any pointers are greatly appreciated at this point. > > > > -- > > Cheers, Mark > > > > Mark Drummond > > mark at markdrummond.ca > > > > When I get sad, I stop being sad and be Awesome instead. TRUE STORY. > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > ____________________________________________________________ > Can't remember your password? Do you need a strong and secure password? > Use Password manager! It stores your passwords & protects your account. > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Thanks all for the responses. As Murphy would have it, after posting my query I found the problem. I had a function defined that did some value mapping and I had a stray line of code in the function. Actually a legitimate line of code that was just in the wrong place. Cheers, Mark On Sun, Apr 26, 2015 at 5:39 PM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:> Not reproducible [1], so any response likely to be a guess. However, you likely have not put everything that is in your interactive environment into the knitr document, so you are not working with the same data in those two environments. > > [1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example > --------------------------------------------------------------------------- > Jeff Newmiller The ..... ..... Go Live... > DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... > Live: OO#.. Dead: OO#.. Playing > Research Engineer (Solar/Batteries O.O#. #.O#. with > /Software/Embedded Controllers) .OO#. .OO#. rocks...1k > --------------------------------------------------------------------------- > Sent from my phone. Please excuse my brevity. > > On April 26, 2015 1:41:32 PM PDT, Mark Drummond <mark at markdrummond.ca> wrote: >>knittr is giving me the above error. The code it is failing on is >>multiplying two numeric features of a data frame. I can run the code >>by hand and it works fine, but when I try to knit my document, knittr >>chokes on the same line. >> >>When kitting: >> >>Quitting from lines 161-175 (RepData_PeerAssessment2.Rmd) >>Error in storm_data$PROPDMG * storm_data$property_damage_cost_factor : >> non-numeric argument to binary operator >>Calls: <Anonymous> ... handle -> withCallingHandlers -> withVisible -> >>eval -> eval >>Execution halted >> >>Running the same lines manually (CTRL+Enter) from the .Rmd file: >> >>> storm_data$total_damage <- >>+ (storm_data$PROPDMG * storm_data$property_damage_cost_factor) + >>+ (storm_data$CROPDMG * storm_data$crop_damage_cost_factor) >>> str(storm_data$total_damage) >> num [1:902297] 25 2.5 25 2.5 2.5 2.5 2.5 2.5 25 25 ... >>> >> >>Call me baffled. Any pointers are greatly appreciated at this point. >-- Cheers, Mark Mark Drummond mark at markdrummond.ca When I get sad, I stop being sad and be Awesome instead. TRUE STORY.