{"id":23,"date":"2020-03-03T14:17:17","date_gmt":"2020-03-03T13:17:17","guid":{"rendered":"https:\/\/www.benscoat.eu\/?p=23"},"modified":"2020-11-27T18:53:17","modified_gmt":"2020-11-27T17:53:17","slug":"how-to-reconcile-clam-and-rbacon-input-files","status":"publish","type":"post","link":"https:\/\/www.benscoat.eu\/index.php\/2020\/03\/03\/how-to-reconcile-clam-and-rbacon-input-files\/","title":{"rendered":"How to reconcile clam and rbacon input files"},"content":{"rendered":"\n<p>As palaeoecologist, I work on data retrieved from natural archives, going back in time. It can be a lake sediment core or peat. The time scale of the data, actually, is built by interpolation of a few radiocarbon dates, measured at particular places along the core. This creates an <em>age-depth model<\/em>. I routinely use two R packages from <a href=\"http:\/\/chrono.qub.ac.uk\/blaauw\/wiggles\/\">Maarten Blaauw<\/a> to do this:<\/p>\n\n\n\n<ul><li><code>clam<\/code>, for <em>classical age-modelling<\/em>,<\/li><li>and <code>rbacon<\/code>, for <em>Bayesian accumulation<\/em> (and it&#8217;s an R package, obviously).<\/li><\/ul>\n\n\n\n<p>Each package defines its own function (<code>clam()<\/code> and <code>Bacon()<\/code>, respectively) which only needs the name of the core, to find a CSV file on your computer with the same name. This is in this CSV file that one saves the results of the radiocarbon datings to use them with either clam or rbacon. However, each package expects the data to be presented in a slightly different fashion. But in a file having the same name. Computers don&#8217;t allow that. And sometimes, I want to be able to use either clam or rbacon.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>There are some workarounds, but they imply either to constantly manipulate the data file(s), or to maintain several files, eventually in different folders. The is neither an enjoyable situation, nor safe. The risk is high of forgetting what you&#8217;ve done last time (<em>so, is it a clam file or an rbacon file???<\/em>) or, worse, to lose data. \ud83d\ude41<\/p>\n\n\n\n<p>Script is much safer, because it is a written protocol of what you&#8217;re doing! This is the structure of my directories:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"r\" class=\"language-r\">~\/Project Name\/Chronologies\/Core Name<\/code><\/pre>\n\n\n\n<p>Of course, an RProject file lies in the <code>Project Name<\/code> directory to open RStudio and automatically set the working directory. Then, <strong>I maintain only one CSV file<\/strong> in the <code>Core Name<\/code> directory. The rest is just a bit of R-magic.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"r\" class=\"language-r\">library(tidyverse)\nlibrary(clam)\n\ncore_name &lt;- \"Core Name\"\n\n(\n  radioc_data &lt;- str_c(\"Chronologies\/\", core_name, \"\/\", core_name, \" Dating results.csv\") %>% \n    read_csv()\n)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"r\" class=\"language-r\"># A tibble: 3 x 7\n   lab_ID       age_uncal    sd c_content delta13c method   depth\n   &lt;chr>            &lt;dbl> &lt;dbl>     &lt;dbl>    &lt;dbl> &lt;chr>    &lt;dbl>\n 1 Ftsy-41930         890    20       992    -36.4 graphite  20 \n 2 Ftsy-59862         970    50       992    -29.3 graphite  40 \n 3 Ftsy-30725        1020    30       234    -28.5 graphite  75<\/code><\/pre>\n\n\n\n<p>Starting from this, I can easily <strong>produce a CSV file to be used by the function <code>clam()<\/code><\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"r\" class=\"language-r\"> (\n  clam_file &lt;- radioc_data %>% \n    mutate(cal_BP = \"\", reservoir = \"\") %>% \n    select(ID = lab_ID, C14_age = age_uncal, cal_BP, error = sd, reservoir, depth) %>% \n    arrange(depth)\n)\nclam_file %>% \n  write_csv(path = str_c(\"Chronologies\/\", core_name, \"\/\", core_name, \".csv\"))\n\nclam(core_name, coredir = \"Chronologies\")<\/code><\/pre>\n\n\n\n<p><strong>For using rbacon<\/strong>, the script is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"r\" class=\"language-r\">library(tidyverse)\nlibrary(rbacon)\n\ncore_name &lt;- \"Core Name\"\n\n(\n  radioc_data &lt;- str_c(\"Chronologies\/\", core_name, \"\/\", core_name, \" Dating results.csv\") %>% \n    read_csv()\n)\n(\n  rbacon_file &lt;- radioc_data %>% \n    select(ID = lab_ID, age = age_uncal, error = sd, depth) %>% \n    mutate(cc = 1) %>% \n    arrange(depth)\n)\nrbacon_file %>% \n  write_csv(path = str_c(\"Chronologies\/\", core_name, \"\/\", core_name, \".csv\"))\n\nBacon(core_name, coredir = \"Chronologies\")<\/code><\/pre>\n\n\n\n<p>See that the <code>rbacon_file<\/code> data frame that this script produces is a bit different than <code>clam_file<\/code>.<\/p>\n\n\n\n<p>This is how I reconciled working with both clam and rbacon packages from the same radiocarbon result file!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As palaeoecologist, I work on data retrieved from natural archives, going back in time. It can be a lake sediment core or peat. The time scale of the data, actually, is built by interpolation of a few radiocarbon dates, measured at particular places along the core. This creates an age-depth model. I routinely use twoContinue reading &rarr;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2,5],"tags":[],"_links":{"self":[{"href":"https:\/\/www.benscoat.eu\/index.php\/wp-json\/wp\/v2\/posts\/23"}],"collection":[{"href":"https:\/\/www.benscoat.eu\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.benscoat.eu\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.benscoat.eu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.benscoat.eu\/index.php\/wp-json\/wp\/v2\/comments?post=23"}],"version-history":[{"count":3,"href":"https:\/\/www.benscoat.eu\/index.php\/wp-json\/wp\/v2\/posts\/23\/revisions"}],"predecessor-version":[{"id":231,"href":"https:\/\/www.benscoat.eu\/index.php\/wp-json\/wp\/v2\/posts\/23\/revisions\/231"}],"wp:attachment":[{"href":"https:\/\/www.benscoat.eu\/index.php\/wp-json\/wp\/v2\/media?parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.benscoat.eu\/index.php\/wp-json\/wp\/v2\/categories?post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.benscoat.eu\/index.php\/wp-json\/wp\/v2\/tags?post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}