BiologicalRecordsCentre / BRCindicators

An R package for creating indicators from trends data
4 stars 11 forks source link

summarise_occDet() - object 'out' not found #36

Open galinajonsson opened 4 years ago

galinajonsson commented 4 years ago

I'm having issues with the summarise_occDet() function. It appears that the read_bayes function isn't working for me as I get the below error message when trying to run summarise_occDet() with my own occDet result files. I do not get the same error message when I run the function using the data created in the vignette. The only difference is that my data were formatted with a closure_period term in addition to the survey term. I can't see any obvious differences between the structure of my result files and the fake vignette ones.

Error in ifelse(is.null(out$min_year), 1, out$min_year) : 
  object 'out' not found
AugustT commented 4 years ago

object 'out' not found

This makes me think you might not have called your object 'out'. Seems odd that that should be a requirement though. Can you copy your full script here so I can get a feel for the context?

AugustT commented 4 years ago

The rdata files in input_dir need to contain an object called 'out', I guess this is not the case for you. Its an annoying requirement, we should really be using .rds files so that you can call them whatever you want

galinajonsson commented 4 years ago

My script: summarise_occDet(input_dir = "path/to/rdataFiles")

Example of structure of my rdata files (minus the "etc."):

> str(results_Hesperia_comma)
List of 13
 $ model               :List of 8
  ..$ ptr      :function ()  
  ..$ data     :function ()  
  ..$ model    :function ()  
  **etc.**
 $ BUGSoutput          :List of 24
  ..$ n.chains       : int 3
  ..$ n.iter         : num 20000
  ..$ n.burnin       : num 10000
  **etc.**
 $ parameters.to.save  : chr [1:9] "psi.fs" "tau2" "tau.lp" "alpha.p" ...
 $ model.file          : chr "/tmp/RtmpSyv3v5/file7de163ee7b9d.txt"
 $ n.iter              : num 20000
 $ DIC                 : logi TRUE
 $ SPP_NAME            : chr "Hesperia.comma"
 $ min_year            : int 1
 $ max_year            : int 110
 $ nsites              : int 3499
 $ nvisits             : int 1630859
 $ species_sites       : int 146
 $ species_observations: num 5439

Do you mean it should be: results_Hesperia_comma$out$min_year as opposed to results_Hesperia_comma$min_year? If so, could it be due to that I first saved the model output as .rds files, read the rds. files and then saved them as .rdata?

Thank you Tom!

drnickisaac commented 4 years ago

Try : out <- results_Hesperia_comma

Then try again. Tom is right: this is an odd choice we've coded.

On Wed, 2 Oct 2019, 16:30 galinajonsson, notifications@github.com wrote:

My script: summarise_occDet(input_dir = "path/to/rdataFiles")

Example of structure of my rdata files (minus the "etc."):

str(results_Hesperia_comma) List of 13 $ model :List of 8 ..$ ptr :function () ..$ data :function () ..$ model :function () etc. $ BUGSoutput :List of 24 ..$ n.chains : int 3 ..$ n.iter : num 20000 ..$ n.burnin : num 10000 etc. $ parameters.to.save : chr [1:9] "psi.fs" "tau2" "tau.lp" "alpha.p" ... $ model.file : chr "/tmp/RtmpSyv3v5/file7de163ee7b9d.txt" $ n.iter : num 20000 $ DIC : logi TRUE $ SPP_NAME : chr "Hesperia.comma" $ min_year : int 1 $ max_year : int 110 $ nsites : int 3499 $ nvisits : int 1630859 $ species_sites : int 146 $ species_observations: num 5439

Do you mean it should be: results_Hesperia_comma$out$min_year as opposed to results_Hesperia_comma$min_year? If so, could it be due to that I first saved the model output as .rds files, read the rds. files and then saved them as .rdata?

Thank you Tom!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/BiologicalRecordsCentre/BRCindicators/issues/36?email_source=notifications&email_token=AA6PTKGRFYCHNH27RMYO4ELQMS5CFA5CNFSM4I4XMUFKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAFFLCY#issuecomment-537548171, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6PTKAF4Z7KBKFBYIYZYE3QMS5CFANCNFSM4I4XMUFA .

AugustT commented 4 years ago

Yes, what Nick said. We might be able to have our cake and eat it by adding a workaround to the function you are using.

loadRData <- function(fileName){
#loads an RData file, and returns it
    load(fileName)
    get(ls()[ls() != "fileName"])
}
d <- loadRData("~/blah/ricardo.RData")

We would need a form of this to the existing code around... here https://github.com/BiologicalRecordsCentre/BRCindicators/blob/16e8853ad3725dfffcfcb12387951ddf883e344f/R/summarise_occDet.R#L30

The benefit here is that @galinajonsson would not have to go through and rename the objects in all her files.

drnickisaac commented 4 years ago

This sounds like a good job for the upcoming Sprint

galinajonsson commented 4 years ago

Thanks for the suggestions, the issue was pretty easy to get around. I have worked through the vignette using my data and will raise a few additional issues based on my experiences. One issue is sparta-related so I will raise an issue in the sparta project too (bma() requires se whilst sparta gives sd and I'm always a bit confused as to what the sample size to use for getting se from sd when it comes to these models). Overall, the vignette was very good and easy to follow. I hope the issues I raise will be helpful for your sprint.

mlogie commented 4 years ago

@AugustT in case it's useful, if you want to know the name of a R object you're loading, you can do: name <- load(fileName, verbose = TRUE)

AugustT commented 4 years ago

That is sort of what is going on in the code I put in about. get is used on the name of the new object (though they use ls() to get it), and the function returns this, allowing the assignment