Skip to content

Commit

Permalink
remove automatic conversion of 'waneyedge' to logical vector, from fd…
Browse files Browse the repository at this point in the history
…_report, sw_combine and sw_sum
  • Loading branch information
hanecakr committed Nov 12, 2023
1 parent c1d6df8 commit 5c1077c
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 184 deletions.
2 changes: 1 addition & 1 deletion .Rproj.user/429CC01A/pcs/files-pane.pper
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"ascending": false
}
],
"path": "C:/Users/hanecakr/Documents/R_github/fellingdateR/tests/testthat"
"path": "C:/Users/hanecakr/Documents/R_github/fellingdateR"
}
2 changes: 1 addition & 1 deletion .Rproj.user/429CC01A/pcs/source-pane.pper
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"activeTab": 21,
"activeTab": 22,
"activeTabSourceWindow0": 0
}
4 changes: 2 additions & 2 deletions .Rproj.user/429CC01A/pcs/windowlayoutstate.pper
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"left": {
"splitterpos": 349,
"splitterpos": 216,
"topwindowstate": "NORMAL",
"panelheight": 830,
"windowheight": 868
},
"right": {
"splitterpos": 307,
"splitterpos": 306,
"topwindowstate": "NORMAL",
"panelheight": 830,
"windowheight": 868
Expand Down
2 changes: 1 addition & 1 deletion .Rproj.user/429CC01A/pcs/workbench-pane.pper
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"TabSet1": 4,
"TabSet2": 1,
"TabSet2": 0,
"TabZoom": {}
}
13 changes: 3 additions & 10 deletions R/fd_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,8 @@ fd_report <- function(x,
}
waneyedge <- df[[waneyedge]] # check is.logical
if (!is.logical(waneyedge)) {
warning(
"--> 'waneyedge' should be a logical vector (TRUE/FALSE),
indicating the presence of waney edge.\n",
"--> Converted to TRUE/FALSE based on presence of string 'wK'."
)
waneyedge <-
ifelse(grepl("wk", waneyedge, ignore.case = TRUE),
TRUE,
FALSE)
stop("--> 'waneyedge' should be a logical vector (TRUE/FALSE),
indicating the presence of waney edge.\n")
}
if (is.na(credMass) || credMass <= 0 || credMass >= 1)
stop("--> credMass must be between 0 and 1")
Expand All @@ -148,7 +141,7 @@ indicating the presence of waney edge.\n",
if (length(sw_OK) < length(sw_data)) {
stop(
sprintf(
"'%s' is not a supported sapwood model, or file doesn't exist\n",
"'%s' is not a supported sapwood model, or file does not exist\n",
sw_data[-sw_OK]
)
)
Expand Down
12 changes: 2 additions & 10 deletions R/sw_combine.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,9 @@ Some values are possibly missing or the values are not numeric"

cambium <- x[, waneyedge]
if (!is.logical(cambium)) {
warning(
"--> Column 'waneyedge' should be logical (TRUE/FALSE), indicating
the presence of waney edge.\n",
"--> Converted to TRUE/FALSE based on presence of string 'wK'."
)
x[, waneyedge] <-
ifelse(grepl("wk", x[, waneyedge], ignore.case = TRUE),
TRUE,
FALSE)
stop("--> 'waneyedge' should be logical vector (TRUE/FALSE), indicating
the presence of waney edge.\n")
}
cambium <- x[, waneyedge]

timeAxis <- seq(min(endDate) - 3, max(endDate) + 100, by = 1)

Expand Down
2 changes: 1 addition & 1 deletion R/sw_interval.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ sw_interval <- function(n_sapwood = NA,
file.exists(sw_data))) {
stop(
sprintf(
"'%s' is not a supported sapwood model, or file doesn't exist\n",
"'%s' is not a supported sapwood model, or file does not exist\n",
sw_data
)
)
Expand Down
28 changes: 2 additions & 26 deletions R/sw_sum.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,8 @@ sw_sum <- function (x,

cambium <- df[[waneyedge]]
if (!is.logical(cambium)) {
which_wk <- which(grepl("wk", cambium, ignore.case = TRUE))
converted_T <- cambium[which_wk]
converted_F <- cambium[-which_wk]
cambium <-
ifelse(grepl("wk", cambium, ignore.case = TRUE),
TRUE,
FALSE)
warning(
paste0(
"Column 'waneyedge' in data.frame should be:\n",
"a logical vector (TRUE/FALSE), indicating the presence of waney edge.\n"
)
)
warning(
sprintf(
"'%s' --> Converted to TRUE based on presence of string 'wK'.\n",
converted_T
)
)
warning(
sprintf(
"'%s' --> Converted to FALSE based on absence of string 'wK'.\n",
converted_F
)
)

stop("--> 'waneyedge' should be logical vector (TRUE/FALSE), indicating
the presence of waney edge.\n")
}

swr <- df[[n_sapwood]]
Expand Down
36 changes: 35 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ This function also works with ring-width data in CHRONO and HALF-CHRONO format.

Furthermore, the `read_fh()` function is case insensitive.


In the example below, an .fh file with dated tree-ring series from a medieval ship DOEL1 is read with `read_fh()`. The ring width measurement, in different formats, are converted to a `data.frame`.

```{r}
Doel1 <- system.file("extdata", "DOEL1.fh", package = "fellingdateR")
Expand All @@ -273,9 +276,40 @@ head(Doel1_trs, 15)
```

When `header = TRUE`, the `get_header()` function is triggered and HEADER fields in the .fh file are returned as a `data.frame`.
When `header = TRUE`, the `get_header()` function is triggered and HEADER fields in the .fh file are returned as a `data.frame`, instead of the ring width measurements.

```{r}
read_fh(Doel1, verbose = FALSE, header = TRUE)
```

The `data.frame` with the HEADER fields can then be used as input for the sw_functions:

```{r}
Doel1_header <- read_fh(Doel1, verbose = FALSE, header = TRUE)
Doel1_header |>
# first convert column 'waneyedge' to a logical vector (in the original .fh file header fields the presence of waney edge is indicated by "WK" - a character string - in the corresponding HEADER field)
dplyr::mutate(waneyedge = dplyr::if_else(grepl("wk", waneyedge, ignore.case = TRUE),
TRUE, FALSE)
) |>
sw_combine(plot = TRUE)
```

The attempt to combine the dated tree-ring series from DOEL1 into a single felling-date range fails. These tree-ring series cannot represent a single event.

However, leaving out the tree-ring series of the keelplank (series "K1_091") of this medieval ship shows that the hull planking and some frame elements could share a common felling date:

```{r}
Doel1_header |>
dplyr::mutate(waneyedge = dplyr::if_else(grepl("wk", waneyedge, ignore.case = TRUE),
TRUE, FALSE)
) |>
dplyr::filter(series != "K1_091") |>
sw_combine(plot = TRUE)
```

For more details see: Haneca K. & Daly A. (2014). Tree-Rings, Timbers and Trees: a dendrochronological survey of the 14th-century cog, Doel 1. _International Journal of Nautical Archaeology_ 43, 87–102. https://doi.org/10.1111/1095-9270.12037


Loading

0 comments on commit 5c1077c

Please sign in to comment.