Closed galinajonsson closed 5 years ago
Your right, this looks like the sort of change that needs a little thought. Changing this to fill = 0 means that entries that were previously FALSE will now be 0. I dont think this is what we want to do as we want the result to be all Trues and Falses.
If you are debugging can you see what temp
looks like just before this line is run? use str
to look at its structure. There might be something wrong with that?
You're absolutely right - although the above change allowed the function to run, the resulting df$spp_vis
was full of 1s and 0s...
temp
looks fine to me or what do you think Tom?
Browse[2]> str(temp)
'data.frame': 43686 obs. of 3 variables:
$ species_name: Factor w/ 54 levels "Aglais io","Aglais urticae",..: 46 46 17 17 17 46 40 39 32 7 ...
$ visit : chr "HU31HU3716 25/08/1973" "HU44HU4741 25/06/1974" "HY20HY2509 8/1905" "HY20HY2509 9/1927" ...
$ pres : logi TRUE TRUE TRUE TRUE TRUE TRUE ...
I identified the issue! Some survey names contained NAs (e.g. "SiteA1997-07-NA") and the function ran fine when I removed these. Thanks for the help Tom.
Oh interesting...I would not have thought that would cause problems..
I came across the following error when running
formatOccDat()
(on windows this time)Error in vapply(indices, fun, .default) : values must be type 'logical', but FUN(X[[1380]]) result is type 'integer'
I fixed it by changing fill=FALSE to fill=0 here: https://github.com/BiologicalRecordsCentre/sparta/blob/a8a3d0063e2d384af2332b02e417bad163170a6d/R/formatOccData.r#L151 As per this thread's advice: https://stackoverflow.com/questions/4835202/error-with-custom-aggregate-function-for-a-cast-call-in-r-reshape2I'm happy to make a push request with the new code but thought I'd ask since I don't know whether it could affects other stuff (and frankly I don't fully understand the above thread).