mikeyEcology / rapidPop

1 stars 0 forks source link

Error in :: argument length 0 #1

Open pomasta opened 4 years ago

pomasta commented 4 years ago

I am encountering this error message when I try to run the app.

Error in :: argument of length 0 103: [.data.frame 101: occMod 100: renderPrint [E:\Coding\R-4.0.2\library\rapidPop\shiny-apps\occMod/server.R#66] 99: func 83: origRenderFunc 82: output$print 2: shiny::runApp 1: rapidPop::runShiny

Code below

============================

#attach packages
library(tidyverse)
library(devtools)
library(here)

#install and load in rapidPop
devtools::install_github("mikeyEcology/rapidPop") 
library(rapidPop)

Import Data

#read in data frame
pig_data <- read_csv(here("cleaned_data","2014_camera_trap_occurrence.csv")) %>% 
  clean_names()

#clean to only include pigs and format to run in the app 
pig_tidy <- pig_data %>% 
  filter(species == "Sus scrofa")  %>% 
  dplyr::select(c("check","date","station_id","number_individuals")) %>% 
  arrange(date)

#just keep april observations
apr_check <- pig_tidy %>% 
  filter(check == "April")

#make sure date is saved/formatted properly 
apr_check$date <- as.Date(apr_check$date, "%Y/%m/%d")

#create a function to count number of days 
Diff <- function(x, start) as.numeric(x - as.Date(cut(start, "year")))
apr_new <- transform(apr_check, total_days = Diff(date, date[1])) %>% 
  clean_names()

#tidy and pivot wider to allow for compatability based on model input data 
apr_form <- apr_new %>% 
  dplyr::select(c("station_id","number_individuals","total_days")) %>% 
  pivot_wider(names_from = total_days, values_from = number_individuals)

#replace NAs with 0 
apr_form[is.na(apr_form)] <- 0

#Save cleaned data frame as a .txt for the shiny app  
write.table(apr_form,here("cleaned_data","2014_apr_check_RP.txt"),row.names = FALSE)

Run Shiny App associated with RapidPop

rapidPop::runShiny("occMod")

This is the data frame that I am running through the application 2014_apr_check_RP.txt

I have tried running this as a .csv and with out modifying the dates as both a .txt and .csv file but keep getting the same error message. Have tried taking the data from my desktop thinking it was an issue with file path length, but that didn't solve it either.

Any thoughts or help is greatly appreciated.

mikeyEcology commented 4 years ago

Have you tried running with the example input file? What happens when you use this one?

pomasta commented 4 years ago

When I run the sample one it does work, I get the following as an output :

The estimated occupancy (psi) is 0.7. The 95% confidence interval for occupancy is 0.376 - 0.9.

The estimated detection probability (p) is 0.476 with a confidence interval of 0.372 - 0.582.

pomasta commented 4 years ago

So after cleaning the data file up some more into a format similar to yours using the following code it was able to run. I think the issue came with spacing in the .txt file an having quotes on the column names, and possibly by having the days listed as numbers instead of as day1, etc.

#add 'day' to the observation date
apr_new$total_days <- paste("day", apr_new$total_days, sep = "")

#tidy and pivot wider to allow for compatability based on model input data 
apr_form <- apr_new %>% 
  dplyr::select(c("station_id","number_individuals","total_days")) %>% 
  pivot_wider(names_from = total_days, values_from = number_individuals) %>% 
  rename(Camera = "station_id")

#replace NAs with 0 
apr_form[is.na(apr_form)] <- 0

#Save cleaned data frame as a .txt for the shiny app  
write.table(apr_form, 
            sep ="\t", 
            here("cleaned_data","2014_apr_check_RP.txt"),
            row.names = FALSE,
            quote = FALSE)

When run it gives an output of:

The estimated occupancy (psi) is 1. The 95% confidence interval for occupancy is 0 - 1.

The estimated detection probability (p) is 0.111 with a confidence interval of 0.092 - 0.133.