Overcome tibble error: Error: All columns in a tibble must be vectors. x Column `solar.time` is NULL

1.8k views Asked by At

unsure if this is a problem due to Tidyverse or my code, but I am receiving this error message while trying to run a bayesian model with my data. The data in question was first coded from excel time using chron and then to POSIXct solar time, which is necessary in order for the model to run. For some reason, the program wants to read the data as a vector and won't run otherwise (see error at very end of code). I am working on Windows with R-version 4.0.3, tidyverse version 1.3.0, and tibble version 3.0.4. Any help would be much appreciated!

#Original Data Set to help with calcs of solar time
data.frame(
  stringsAsFactors = FALSE,
           ï..Date = c("6/28/2018","6/28/2018",
                       "6/28/2018","6/28/2018","6/28/2018"),
              Time = c("12:00:00 AM","12:05:00 AM",
                       "12:10:00 AM","12:15:00 AM","12:20:00 AM"),
              UStc = c(43279,43279.00347,43279.00694,
                       43279.01042,43279.01389),
               USt = c(9.13, 9.1, 9.07, 9.03, 9),
             Light = c(55.37360911,55.93355151,
                       53.89058287,56.48904704,58.9929764),
             Depth = c(0.37036501,0.370455948,
                       0.370455948,0.370000078,0.370000078)
)
suppressPackageStartupMessages({
  library(tidyverse)
  library(streamMetabolizer)
  library(ggpubr)
  library(lubridate)
  library(rstan)
  library(StanHeaders)
  library(chron)
  library(Rcpp)
  library(RcppArmadillo)
  library(reprex)
  library(datapasta)
})
# SET DIRECTORY AND ADJUST DATE/TIME; ADDED UPDATED SOLAR TIME EDITS
kup_in <- read.csv("reprex_data.csv") #download Input file

#Converts excel date/times to R date/times 
options(chron.origin = c(month=1, day=1, year=1900))
TC <- chron((kup_in$UStc-2), format = c(dates="Day/Month/Year", times = "h:m:s"))

#Chron datetimes, change format
chron.time <- chron::chron(TC)
time.format <- "%Y-%m-%d %H:%M:%S"
text.time <- format(chron.time, time.format) #as.POSIXct works poorly with chron
posix.time.localtz <- as.POSIXct(text.time, format=time.format, tz='America/Anchorage')

#CREATE RELEVANT METABOLIZER DATA COMPONENTS
kup_in$SolarTime <-  streamMetabolizer::calc_solar_time(posix.time.localtz, longitude=-149.39)
new.solar.time <- kup_in$SolarTime

#GENERATE BAYESIAN INPUT DATA FILE 
dat_bayes <- NULL
dat_bayes <- data.frame(new.solar.time,DO.obs,DO.sat,depth,tempC,light)
colnames(dat_bayes)<- c("solar.time","DO.obs","DO.sat","depth","temp.water","light")

#Here's some data from dat_bayes that's plugged into the model, in which I figure solar.time is causing the issue
data.frame(solar.time = c("2018-06-27 14:04:04",
                 "2018-06-27 14:09:04","2018-06-27 14:14:04","2018-06-27 14:19:04","2018-06-27 14:24:04"),
      DO.obs = c(10.60079025, 10.61051408, 10.61051408, 10.62138836, 10.6313428),
      DO.sat = c(11.5237926676887,11.5320798498539,
                 11.5403775128666,11.5514573967773,11.5597795819433),
       depth = c(0.37036501, 0.370455948, 0.370455948, 0.370000078, 0.370000078),
  temp.water = c(9.13, 9.1, 9.07, 9.03, 9),
       light = c(55.37360911, 55.93355151, 53.89058287, 56.48904704, 58.9929764),
   discharge = c(4.859476627,4.865344253,4.865344253,
                 4.835973446,4.835973446)
)
# Set the model type.
bayes_name <- mm_name(type='bayes', pool_K600='none',
                      err_obs_iid=TRUE, err_proc_acor=FALSE, err_proc_iid=TRUE, 
                      ode_method = 'trapezoid', deficit_src='DO_mod', engine='stan')

#### Set the model specs. 
bayes_specs_2 <- revise(specs(bayes_name), 
                        burnin_steps=1000, saved_steps=500,
                        day_start=3, day_end=27,
                        GPP_daily_mu = 2, GPP_daily_lower = 0,GPP_daily_sigma =2,
                        ER_daily_mu = -4, ER_daily_upper = 0, ER_daily_sigma = 3,
                        K600_daily_meanlog = log(12),
                        K600_daily_sdlog = 0.01,
                        chains=1) 

#run the model with the specs
bayes_fit_kup_2 <- metab(bayes_specs_2, data=dat_bayes)

#> Error: All columns in a tibble must be vectors.
#> x Column `solar.time` is NULL.**
#> Timing stopped at: 1.41 0.01 1.42
0

There are 0 answers