ISAAKiel / oxcAAR

R Package - Interaction with Oxcal
GNU General Public License v2.0
21 stars 4 forks source link

Fix na errors in format date ad bc #23

Closed MartinHinz closed 5 years ago

MartinHinz commented 5 years ago

Salvador Herrando-Perez wrote:

I am using oxcAAR to calibrate Pleistocene terrestrial megafauna dates from the Northern Hemisphere. Using the example below (5 dates), when the precision of the uncalibrated dates is above a given threshold, oxcalCalibrate crashes and spits a processing error. Curiously, the threshold generating the error is different depending on the position of the problematic precision in the data vector (see yellow highlight in ‘MySD’ below) – for instance, oxcalCalibrate crashes if the precision of the first uncalibrated date is higher than 2848 ( error 1), but crashes after calibrating the first date if the precision of the second uncalibrated date is larger than 2888 ( error 2). I would appreciate if you could kindly provide advice about how to solve this problem. Many thanks indeed for your time to attend my request. Sincerely. Salvador

EXAMPLE MyDates <- c(27840, 28040, 28060, 28170, 30567); MyDates; class(MyDates); length(MyDates) MySD <- c(2848, 2888, 170, 220, 123); MySD; class(MySD); length(MySD) MyNames <- c("OxA-megafauna1","OxA-megafauna2","OxA-megafauna3","OxA-megafauna4", "OxA-megafauna5"); MyNames; class(MyNames); length(MyNames) oxcalCalibrate (bp = MyDates, std = MySD, names = MyNames)

ERROR 1 MyDates <- c(27840, 28040, 28060, 28170, 30567); MyDates; class(MyDates); length(MyDates) MySD <- c(2849, 2888, 170, 220, 123); MySD; class(MySD); length(MySD) MyNames <- c("OxA-megafauna1","OxA-megafauna2","OxA-megafauna3","OxA-megafauna4", "OxA-megafauna5"); MyNames; class(MyNames); length(MyNames) oxcalCalibrate (bp = MyDates, std = MySD, names = MyNames) OxCal v4.3.2 (c) Bronk Ramsey (2017) List of 5 calibrated dates: Error in strsplit(left, "\n") : non-character argument In addition: Warning message: In matrix(as.double(stats::na.omit(unlist(strsplit(stringr::str_match(result_text, : NAs introduced by coercion

ERROR 2 MyDates <- c(27840, 28040, 28060, 28170, 30567); MyDates; class(MyDates); length(MyDates) MySD <- c(2848, 2889, 170, 220, 123); MySD; class(MySD); length(MySD) MyNames <- c("OxA-megafauna1","OxA-megafauna2","OxA-megafauna3","OxA-megafauna4", "OxA-megafauna5"); MyNames; class(MyNames); length(MyNames) oxcalCalibrate (bp = MyDates, std = MySD, names = MyNames) OxCal v4.3.2 (c) Bronk Ramsey (2017) List of 5 calibrated dates:

============================= R_Date: OxA-megafauna1

BP = 27840, std = 2848 unmodelled:
one sigma
34285 BC - 27020 BC (68.2%)
two sigma
41943 BC - 25500 BC (95.4%)
three sigma
48048 BC - 25130 BC (99.7%)
Calibrated with: IntCal13 atmospheric curve (Reimer et al 2013)

Error in strsplit(left, "\n") : non-character argument In addition: Warning message: In matrix(as.double(stats::na.omit(unlist(strsplit(stringr::str_match(result_text, : NAs introduced by coercion

Change formatDateAdBC to treat NAs correctly, also changed the format function in general so that "posterior" is always written. Additionally fixed side_by_side_output so that sigma results are correctly returned if no posterior is existing. Before, due to wrong usage of ifelse, only first line was printed.

MartinHinz commented 5 years ago

Please do not merge I got the message that Salvador Herrando-Perez was sucessful with this implementation!

codecov-io commented 5 years ago

Codecov Report

Merging #23 into master will decrease coverage by 0.28%. The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #23      +/-   ##
==========================================
- Coverage   81.71%   81.42%   -0.29%     
==========================================
  Files          13       13              
  Lines         853      840      -13     
==========================================
- Hits          697      684      -13     
  Misses        156      156
Impacted Files Coverage Δ
R/oxcAARCalibratedDate.R 85.71% <100%> (+0.64%) :arrow_up:
R/parsing_functions.R 84.48% <100%> (-0.63%) :arrow_down:
R/utility_functions.R 87.69% <66.66%> (-0.84%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update a7d1e34...0cacf04. Read the comment docs.

nevrome commented 5 years ago

Nice! Test-driven development! Why not merge if it works?

MartinHinz commented 5 years ago

Taking this up after some delay. Salvadore wrote:

Thanks for your kind and positive response.

So far, so good.

I have tried the new version, and the problem has been solved for the sigma thresholds stated in my first email, however the script continues to crash for large ages and/or very low precisions. For instance, for uncalibrated ages of 40, 50 and 60 ky, the crashing occurs at precisions somewhere within intervals 9 to 10, 1.7 to 1.8 and 6 to 7 ky, respectively. These are extreme values in some cases but not in others, e.g., an age of, say, 50 +/- 3 ky is common for many of the Late-Pleistocene megafauna species I am dealing with. An additional caveat is that xlim and ylim in oxcalCalibrate() seems to have an upper bound around 45 ky - so for old ages and/or very low precisions the calibration curve might fail to display or not show the error bars.

Will write test for that and report soon.

MartinHinz commented 5 years ago

Or, actually even better, make up an new issue and a new dev branch to fix these errors. So I will merge this now.

MartinHinz commented 5 years ago

Further bug fixing will be done in relation to #24 and #25.