Knitr - usemethod中的错误(“round_any”):没有应用round_any的适用方法

时间:2015-07-21 08:27:33

标签: r knitr

我正在尝试在knitr中输出我的一些代码结果。现在奇怪的是,代码在标题中生成错误。但是单独运行round_any()并在knitr中输出它很好。

knitr code

```{r, echo = FALSE, message=FALSE, warning=FALSE}
source("BooliQuery.R")

    BooliQuery()    
```

我的代码

library(digest)
library(stringi)
library(jsonlite)
library(plyr)

BooliQuery  <- function(area = "stockholm", type="lägenhet", sincesold = "",  FUN  = "", limit = 250, offset = 0, mode = 1) {


  #raw data fetch + adjust.
  lOriginal  <- GETAPI(area, type, sincesold, FUN, limit, offset)
  lOriginal$AreaSize <- round_any(lOriginal$livingArea, 10, floor)
  lOriginal$PriceDiff  <- lOriginal$soldPrice - lOriginal$listPrice

  #Create frame overview
  Overview.Return  <- Frame.Overview(lOriginal)

  #Mode - return selector
  ifelse( mode == 1,  return (Overview.Return), return (lOriginal) )

}
Frame.Overview  <- function(lOriginal) {

  #Aggregate mean
  listPrice  <- aggregate(lOriginal, list(lOriginal$AreaSize), FUN = mean, na.rm = TRUE)
  colnames(listPrice)[1]  <- "SegGroup"
  listPrice  <- listPrice[, c("SegGroup", "listPrice", "soldPrice", "PriceDiff", "rent", "livingArea", "constructionYear") ] 

  #Perform Rounding
  listPrice[, c(2:5)]  <- round(listPrice[,c(2:5)], digits = 0)
  listPrice[, 6]  <- round(listPrice[, 6], digits = 1)
  listPrice[, 7]  <- signif(listPrice[,7], digits = 4)

  return(listPrice)
}


GETAPI  <- function(area = "stockholm", type="lägenhet", sincesold = "",  FUN  = "", limit = 250, offset = 0) {

  #ID Info
  key  <- "PRIVATE KEY"
  caller.ID  <- "USERNAME"
  #//

  unix.timestamp  <- as.integer( as.POSIXct(Sys.time()) )
  random.string  <- stri_rand_strings( n = 1, length = 16)

  #Sha1-Hash: CallerID + time + key + unique, 40-char hexadecimal
  hash.string  <- paste0(caller.ID, unix.timestamp, key, random.string)  
    hash.sha1  <- digest(hash.string,"sha1",serialize=FALSE)

  #Create URL
  api.string  <- "https://api.booli.se/sold?q="
  url.string  <- paste0(api.string, area, "&objectType=" , type , "&minSoldDate=", sincesold, FUN, "&limit=", limit, "&offset=", offset,"&callerId=", caller.ID, "&time=" , 
                        unix.timestamp, "&unique=", random.string, "&hash=", hash.sha1)
  #Parse JSON
  parsed.JSON  <- fromJSON(txt = url.string)

  return(parsed.JSON$sold)


}

在控制台中单独运行代码很好。那可能是什么错?

0 个答案:

没有答案