Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interpreting (invalid trim argument) error in R : by a newbie

Tags:

r

My code is as follows:

lat <- 24.419
lon <- 54.502
days <- 1
Tmax <- 44.3
Tmin <- 26.0
tal <- 0.72
BCb_guess <- 0.13
epsilon <- 0.5
rad_mea <- 254
sirad::bccal(lat, days, rad_mea, extraT = NULL, Tmax, Tmin, tal)

When I execute my function bccal() from the sirad package, I get the following error:

Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L,  : 
  invalid 'trim' argument

I am completely new to R any help in solving the issue will be highly appreciated, Thanks

like image 960
Hawkins Avatar asked Oct 17 '15 20:10

Hawkins


2 Answers

Not sure if this is causing the error you're getting, but I think you have the date argument wrong. You're giving it the number of days you want to calculate for, but bccal (and most other functions in R) can infer this from the length of other arguments.

The date argument should be a vector of the actual dates you want to calculate this for. For example:

# for one day
lat <- 24.419
lon <- 54.502
days <- as.Date('2015-06-22')
Tmax <- 44.3
Tmin <- 26.0
tal <- 0.72
BCb_guess <- 0.13
epsilon <- 0.5
rad_mea <- 254
sirad::bccal(lat, days, rad_mea, extraT = NULL, Tmax, Tmin, tal)

# for several days
lat <- 24.419
lon <- 54.502
days <- c(as.Date('2015-06-22'), as.Date('2015-07-16'))
Tmax <- c(44.3, 43.7)
Tmin <- c(26.0, 25.1)
tal <- 0.72
BCb_guess <- 0.13
epsilon <- 0.5
rad_mea <- c(254, 253)
sirad::bccal(lat, days, rad_mea, extraT = NULL, Tmax, Tmin, tal)
like image 162
jimjamslam Avatar answered Sep 26 '22 11:09

jimjamslam


I have debugged this. the bccal function is defined here .

https://github.com/cran/sirad/blob/master/R/bccal.R

the problem is coming in line 16 .

dtempM <- mean(as.numeric(aggregate(Zdtemp, by = format(time(Zdtemp), 
    "%m"), FUN = mean, na.rm = TRUE)), na.rm = T)

specifically here

format(time(Zdtemp), "%m")

I dont really know what you want to achieve(dont have a clue about bccal ,all i can say its dependent on Tmax,Tmin and days) ,so thats all I can do for now. may be it would ring a bell for you

like image 45
Bg1850 Avatar answered Sep 26 '22 11:09

Bg1850