---
title: "iemisc: Construction Measurement Examples"
author: "Irucka Embry, E.I.T. (EcoC²S)"
date: "`r Sys.Date()`"
lang: en-us
urlcolor: blue
output:
  rmarkdown::pdf_document:
    highlight: kate
    toc: true
    latex_engine: xelatex
vignette: >
  %\VignetteIndexEntry{iemisc Construction Measurement Examples}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

\bigskip

# Replicate the R code

Note: If you wish to replicate the R code below, then you will need to copy and paste the following commands in R first (to make sure you have all the packages and their dependencies):  

\medskip

```{r eval = FALSE, tidy = TRUE}
install.packages(c("install.load", "iemisc", "units", "knitr"))
# install the packages and their dependencies
```

\bigskip
\bigskip

```{r, warning = FALSE, message = FALSE, tidy = TRUE}
# load the required packages
install.load::load_package("iemisc", "units")
# load needed packages using the load_package function from the install.load package (it is assumed that you have already installed these packages)

import::from(fpCompare, "%==%")
```

\bigskip
\bigskip

# Fraction (or Mixed number) to a Decimal (Numeric Vector)

## Example 1

Convert the following mixed number values to a decimal number. The non-numeric (character) values are ignored with the frac_to_numeric function.  

\medskip

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

trxt <- "1 1/3"

frac_to_numeric(trxt)


tlrxy <- "4 1/8 inches"

frac_to_numeric(tlrxy)


tmrxy <- "12 13/16 inches"

frac_to_numeric(tmrxy)


hjtevo <- "28/3 inches"

frac_to_numeric(hjtevo)
```

\bigskip
\bigskip

# Construction Decimal (Measurement in feet inch fraction returned as a decimal value)

## Example 1 (Convert a feet inch fraction measurement to its decimal equivalent)

In the following example, the expressed values are the same in t1 through t16 (34 feet 3 1/2 inches); however, the only difference exists in the character strings. The point here is to show that the character values do not really matter because it is the numeric values that actually determine the decimal equivalent. The decimal equivalent will be expressed in decimal feet when the result is traditional and it will be expressed in decimal inches when the result is librecad.  

\medskip

```{r, warning = FALSE, message = FALSE, tidy = TRUE}
t1 <- "34'-3 1/2\""
t2 <- "34-3 1/2\""
t3 <- "34' 3 1/2\""
t4 <- "34'-3 1/2"
t5 <- "34-3 1/2"
t6 <- "34 3 1/2"
t7 <- "34 ft 3 1/2 in"
t8 <- "34 3 1/2"
t9 <- "34 fts 3 1/2 in"
t10 <- "34 foot 3 1/2 in"
t11 <- "34 foot 3 1/2 inch"
t12 <- "34 foot 3 1/2 in"
t13 <- "34 feet 3 1/2 in"
t14 <- "34 feet 3 1/2 inch"
t15 <- "34 feet 3 1/2 in"
t16 <- "34 FEEt 3 1/2 IN"
```

\bigskip

## a) Multiply t1 by t2 and return the answer in acres

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

(construction_decimal(t1, result = "traditional", output = "vector")
* construction_decimal(t2, result = "traditional", output = "vector")
* 4) / 43560
# acres
```

\bigskip

## b) Square t1 and return the answer in acres

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

(construction_decimal(t1, result = "traditional", output = "vector")
^ 2 * 4) / 43560
# acres
```

\bigskip

## c) Both a) and b) can be expressed using the following as well

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

t1_ft2 <- set_units((construction_decimal(t1, result = "traditional",
output = "vector") * construction_decimal(t2, result = "traditional",
output = "vector") * 4), US_survey_foot ^ 2)

t1_acres <- t1_ft2

units(t1_acres) <- make_units(acre); t1_acres


t1_ft2s <- set_units((construction_decimal(t1, result = "traditional",
output = "vector") ^ 2 * 4), US_survey_foot ^ 2)

t1_acress <- t1_ft2s

units(t1_acress) <- make_units(acre)
t1_acress
```

\bigskip

## d) Return the sum of t1 - t5

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

sum(construction_decimal(t1, result = "traditional", output = "vector"),
construction_decimal(t2, result = "traditional", output = "vector"),
construction_decimal(t3, result = "traditional", output = "vector"),
construction_decimal(t4, result = "traditional", output = "vector"),
construction_decimal(t5, result = "traditional", output = "vector"))
```

\bigskip

## e) Return the traditional vector result for t1 - t16

\bigskip

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

construction_decimal(t1, result = "traditional", output = "vector")

construction_decimal(t2, result = "traditional", output = "vector")

construction_decimal(t3, result = "traditional", output = "vector")

construction_decimal(t4, result = "traditional", output = "vector")

construction_decimal(t5, result = "traditional", output = "vector")

construction_decimal(t6, result = "traditional", output = "vector")

construction_decimal(t7, result = "traditional", output = "vector")

construction_decimal(t8, result = "traditional", output = "vector")

construction_decimal(t9, result = "traditional", output = "vector")

construction_decimal(t10, result = "traditional", output = "vector")

construction_decimal(t11, result = "traditional", output = "vector")

construction_decimal(t12, result = "traditional", output = "vector")

construction_decimal(t13, result = "traditional", output = "vector")

construction_decimal(t14, result = "traditional", output = "vector")

construction_decimal(t15, result = "traditional", output = "vector")

construction_decimal(t16, result = "traditional", output = "vector")
```

\bigskip

## f) Return the librecad vector result result for t1 - t16

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

construction_decimal(t1, result = "librecad", output = "vector")

construction_decimal(t2, result = "librecad", output = "vector")

construction_decimal(t3, result = "librecad", output = "vector")

construction_decimal(t4, result = "librecad", output = "vector")

construction_decimal(t5, result = "librecad", output = "vector")

construction_decimal(t6, result = "librecad", output = "vector")

construction_decimal(t7, result = "librecad", output = "vector")

construction_decimal(t8, result = "librecad", output = "vector")

construction_decimal(t9, result = "librecad", output = "vector")

construction_decimal(t10, result = "librecad", output = "vector")

construction_decimal(t11, result = "librecad", output = "vector")

construction_decimal(t12, result = "librecad", output = "vector")

construction_decimal(t13, result = "librecad", output = "vector")

construction_decimal(t14, result = "librecad", output = "vector")

construction_decimal(t15, result = "librecad", output = "vector")

construction_decimal(t16, result = "librecad", output = "vector")
```

\bigskip
\bigskip

## Example 2 [Verify the sum]

In the following example, verify that the sum of m1 through m6 [33 feet 3 1/2 inches, 32 feet 1 inch, 32 feet 1 inch, 32 feet 1 inch, 32 feet 1 inch, 33 feet 3 1/2 inches] using the construction_decimal function is equivalent to 194 feet 11 inches. As long as the last value is TRUE, then the verification is complete.  

\medskip

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

m1 <- "33'-3 1/2\""
m2 <- "32'-1"
m3 <- "32'-1"
m4 <- "32'-1"
m5 <- "32'-1"
m6 <- "33'-3 1/2\""

msum <- sum(construction_decimal(m1, result = "traditional",
output = "vector"), construction_decimal(m2, result = "traditional",
output = "vector"), construction_decimal(m3, result = "traditional",
output = "vector"), construction_decimal(m4, result = "traditional",
output = "vector"), construction_decimal(m5, result = "traditional",
output = "vector"), construction_decimal(m6, result = "traditional",
output = "vector"))

# print msum as a decimal number
msum

# print the construction fraction for msum
construction_fraction(msum, type = "traditional", result = "traditional", fraction = 0)

# check whether msum is equal to the decimal expressed by 194 feet 11 inches or not
construction_decimal("194'-11", result = "traditional", output =
"vector") %==% msum
```

\bigskip
\bigskip

## Example 3 [Perimeter sum]

Calculate the sum of an object with the following perimeter measurements [3 inches, 8 inches, 6 inches, 2 5/8 inches, 2 feet 6 3/4 inches, 2 feet 6 3/4 inches, 2 feet 6 3/4 inches, 2 5/8 inches]. The sum will be in decimal feet.  

\medskip

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

sum(construction_decimal("0 3", result = "traditional", output = "vector"), construction_decimal("0 8", result = "traditional", output = "vector"), construction_decimal("0 6", result = "traditional", output = "vector")) * sum(construction_decimal("0 2 5/8", result = "traditional", output = "vector"), 3 * construction_decimal("2 6 3/4", result = "traditional", output = "vector"), construction_decimal("0 2 5/8", result = "traditional", output = "vector"))
```

\bigskip
\bigskip

## Example 4 [Total surface area & volume for riprap]

Calculate the amount of surface area fill, in acres, for riprap placement and the volume of fill in yards^3^ along a streambank.  

\medskip

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

bank <- set_units(construction_decimal("72 3 1/3", result =
"traditional", output = "vector"), US_survey_foot)
# 72 feet 3 1/3 inches

bank
 
riprap <- set_units(construction_decimal("0 15.0", result = "traditional",
output = "vector"), US_survey_foot)

riprap

riprap_yd <- riprap

units(riprap_yd) <- make_units(yd)

riprap_yd

OHWM_width <- set_units(25, US_survey_foot)

OHWM_width

width <- set_units(47, US_survey_foot)

width


bank_area1 <- width * bank

bank_area1

bank_area2 <- bank_area1

units(bank_area2) <- make_units(yd^2)

bank_area2

bank_area3 <- bank_area1

units(bank_area3) <- make_units(acres)

bank_area3

vol_bank <- riprap_yd * bank_area2

vol_bank


bank_area_OHWM1 <- OHWM_width * bank

bank_area_OHWM1

bank_area_OHWM2 <- bank_area1

units(bank_area_OHWM2) <- make_units(yd^2)

bank_area_OHWM2

bank_area_OHWM3 <- bank_area1

units(bank_area_OHWM3) <- make_units(acres)

bank_area_OHWM3

vol_bank_OHWM <- riprap_yd * bank_area_OHWM2

vol_bank_OHWM


fill_ft2 <- bank_area_OHWM1

fill_ft2

fill_acres <- bank_area_OHWM3

fill_acres

fill_yd2 <- bank_area_OHWM2

fill_yd2

fill_yd3 <- vol_bank_OHWM

fill_yd3
```

\bigskip
\bigskip

## Example 5 [Examples from the Spike reference]

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

psst <- "7' 4 5/16\""

pssts <- "0 3 3/8\""

wall1 <- "12' 7\""

wall2 <- "40' 9\""

construction_decimal(psst, result = "traditional", output = "vector")

construction_decimal(pssts, result = "traditional", output = "vector")

construction_decimal(wall1, result = "traditional", output = "vector")

construction_decimal(wall2, result = "traditional", output = "vector")
```

\bigskip

## a) Matching the decimal value for 3 3/8 inches

Since pssts is a fraction representing 3 3/8 inches, it is better to use the frac_to_numeric function or the construction_decimal function with the librecad result instead of using the construction_decimal function with the traditional result to match the decimal value from the Spike reference.  

\medskip

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

pssts1 <- "3 3/8\""

frac_to_numeric(pssts1)

# or more simply

pssts1b <- "3 3/8 in"

# checks
frac_to_numeric(pssts1b)

frac_to_numeric(pssts1) %==% frac_to_numeric(pssts1b)

frac_to_numeric(pssts1) %==% construction_decimal(pssts, result = "librecad", output = "vector")

frac_to_numeric(pssts1b) %==% construction_decimal(pssts, result = "librecad", output = "vector")
```

\bigskip
\bigskip

## Example 6 [Print a table with equivalent length measurements]

In a tabular format, show the equivalents to 1 feet 2 7/16 inches, 6 feet 8 3/4 inches, 6 feet 5 3/256 inches in decimal inches, decimal feet, decimal yards, decimal millimeters, decimal centimeters, and decimal meters.  

\medskip

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

librecad1 <- "1 2 7/16\""

construction_decimal(librecad1, result = "traditional", output = "vector")

knitr::kable(format(construction_decimal(librecad1, result = "traditional", output = "table"), digits = 6, nsmall = 0))

construction_decimal(librecad1, result = "librecad", output = "vector")

knitr::kable(format(construction_decimal(librecad1, result = "librecad", output = "table"), digits = 4, nsmall = 0))


librecad2 <- "6' 8 3/4 in"

construction_decimal(librecad2, result = "traditional", output = "vector")

knitr::kable(format(construction_decimal(librecad2, result = "traditional", output = "table"), digits = 6, nsmall = 6))

construction_decimal(librecad2, result = "librecad", output = "vector")

knitr::kable(format(construction_decimal(librecad2, result = "librecad", output = "table"), digits = 2, nsmall = 2))


librecad3 <- "6'-5 3/256\""

construction_decimal(librecad3, result = "traditional", output = "vector")

knitr::kable(format(construction_decimal(librecad3, result = "traditional", output = "table"), digits = 6, nsmall = 6))

construction_decimal(librecad3, result = "librecad", output = "vector")

knitr::kable(format(construction_decimal(librecad3, result = "librecad", output = "table"), digits = 5, nsmall = 5))
```

\bigskip
\bigskip
\bigskip
\bigskip

# Construction Fraction

## Example 1

Return the fractional equivalents for the decimal value of 6 feet 5 3/256 inches.  

\medskip

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

checker <- "6'-5 3/256 in"

checkers <- construction_decimal(checker, result = "traditional", output = "vector")

checkers

construction_fraction(checkers, type = "traditional", result = "traditional", fraction = 0)

construction_fraction(checkers, type = "traditional", result = "traditional", fraction = 2)

construction_fraction(checkers, type = "traditional", result = "traditional", fraction = 4)

construction_fraction(checkers, type = "traditional", result = "traditional", fraction = 8)

construction_fraction(checkers, type = "traditional", result = "traditional", fraction = 16)

construction_fraction(checkers, type = "traditional", result = "traditional", fraction = 32)

construction_fraction(checkers, type = "traditional", result = "traditional", fraction = 64)

construction_fraction(checkers, type = "traditional", result = "traditional", fraction = 100)

construction_fraction(checkers, type = "traditional", result = "traditional", fraction = 128)

construction_fraction(checkers, type = "traditional", result = "traditional", fraction = 256)
```

\bigskip
\bigskip

## Example 2

Return the fractional equivalents for the decimal value of 77.6875 inches.  

\medskip

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

checkin <- 77.6875

construction_fraction(checkin, type = "librecad", result = "traditional", fraction = 0)

construction_fraction(checkin, type = "librecad", result = "traditional", fraction = 2)

construction_fraction(checkin, type = "librecad", result = "traditional", fraction = 4)

construction_fraction(checkin, type = "librecad", result = "traditional", fraction = 8)

construction_fraction(checkin, type = "librecad", result = "traditional", fraction = 16)

construction_fraction(checkin, type = "librecad", result = "traditional", fraction = 32)

construction_fraction(checkin, type = "librecad", result = "traditional", fraction = 64)

construction_fraction(checkin, type = "librecad", result = "traditional", fraction = 100)

construction_fraction(checkin, type = "librecad", result = "traditional", fraction = 128)

construction_fraction(checkin, type = "librecad", result = "traditional", fraction = 256)
```

\bigskip
\bigskip

## Example 3

Given the lengths of 5 feet 1 3/4 inches and 21 feet 7 3/8. Multiply, divide, add, and subtract the value to compare the results to the CalculatorSoup.com reference.  

## a) Multiplication

The answer is "111.225 ft^2^ (16016.4063 in^2^)".  

\medskip

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

length1 <- "5 feet 1 3/4 inches"
length2 <- "21 feet 7 3/8"

length_product_in <- construction_decimal(length1, result = "librecad", output = "vector") * construction_decimal(length2, result = "librecad", output = "vector")

length_product_in


length_product_ft <- construction_decimal(length1, result = "traditional", output = "vector") * construction_decimal(length2, result = "traditional", output = "vector")

length_product_ft


construction_fraction(length_product_ft, type = "traditional", result = "traditional", fraction = 8)


# Alternatively, this could all be done in a single step as well:

construction_fraction((construction_decimal(length1, result = "traditional", output = "vector") * construction_decimal(length2, result = "traditional", output = "vector")), type = "traditional", result = "traditional", fraction = 8)
```

\bigskip

## b) Division

The answer is "0.2381".  

\medskip

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

length1 <- "5 feet 1 3/4 inches"
length2 <- "21 feet 7 3/8"

length_quotient <- construction_decimal(length1, result = "librecad", output = "vector") / construction_decimal(length2, result = "librecad", output = "vector")

length_quotient


construction_fraction(length_quotient, type = "traditional", result = "traditional", fraction = 8)


# Alternatively, this could all be done in a single step as well:

construction_fraction((construction_decimal(length1, result = "traditional", output = "vector") / construction_decimal(length2, result = "traditional", output = "vector")), type = "traditional", result = "traditional", fraction = 8)
```

\bigskip

## c) Addition

The answer is "26 ft 9 1/8 in".  

\medskip

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

length_sum <- sum(construction_decimal(length1, result = "traditional", output = "vector"), construction_decimal(length2, result = "traditional", output = "vector"))

construction_fraction(length_sum, type = "traditional", result = "traditional", fraction = 8)

# Alternatively, this could all be done in a single step as well:

construction_fraction(sum(construction_decimal(length1, result = "traditional", output = "vector"), construction_decimal(length2, result = "traditional", output = "vector")), type = "traditional", result = "traditional", fraction = 8)
```

\bigskip

## d) Subtraction (Negative result)

The answer is "-16 ft 5 5/8 in".  

\medskip

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

length_difference1 <- construction_decimal(length1, result = "traditional", output = "vector") - construction_decimal(length2, result = "traditional", output = "vector")

construction_fraction(length_difference1, type = "traditional", result = "traditional", fraction = 8)

# Alternatively, this could all be done in a single step as well:

construction_fraction((construction_decimal(length1, result = "traditional", output = "vector") - construction_decimal(length2, result = "traditional", output = "vector")), type = "traditional", result = "traditional", fraction = 8)
```

\medskip

## d) Subtraction (Positive result)

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

length_difference2 <- construction_decimal(length2, result = "traditional", output = "vector") - construction_decimal(length1, result = "traditional", output = "vector")

construction_fraction(length_difference2, type = "traditional", result = "traditional", fraction = 8)

# Alternatively, this could all be done in a single step as well:

construction_fraction((construction_decimal(length2, result = "traditional", output = "vector") - construction_decimal(length1, result = "traditional", output = "vector")), type = "traditional", result = "traditional", fraction = 8)
```

\bigskip
\bigskip

## Example 4

"Imagine you&#8217;ve bought a wooden panel, 5 meters long. You plan to cut it into six equal parts, but you have only a tape measure with the fractional inches scale. We can measure the length with precision down to 1/32"." From the Omni Calculator: Inches to Fraction Calculator reference.  

What is the length for each of the 6 boards cut?  

\medskip

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

panel <- set_units(5, "m")

panel

panel_ft <- panel

units(panel_ft) <- make_units(ft)

panel_ft

panel_6 <- panel_ft / 6

panel_6

construction_fraction(drop_units(panel_6), type = "traditional", result = "traditional", fraction = 16)

construction_fraction(drop_units(panel_6), type = "traditional", result = "traditional", fraction = 32)
```

\bigskip
\bigskip

# Construction Decimal Engineering (LibreCAD Style)

## Examples

```{r, warning = FALSE, message = FALSE, tidy = TRUE}

librecad1a <- "6' 8 3/4 in"

construction_decimal_eng(librecad1a)


librecad2a <- "6'-5 3/256\""

construction_decimal_eng(librecad2a)
```

\bigskip
\bigskip
\bigskip
\bigskip

# R Help for iemisc Functions

Please refer to the `iemisc` [https://CRAN.R-project.org/package=iemisc] help definitions for the `frac_to_numeric`, `construction_decimal`, and `construction_fraction` functions below:  

\bigskip
\bigskip

```{r, echo = FALSE}

loadNamespace("printr")
```

```{r tidy = TRUE, comment = "", results = "asis"}

help(frac_to_numeric, package = "iemisc")

help(construction_decimal, package = "iemisc")

help(construction_fraction, package = "iemisc")
```

\bigskip
\bigskip

# Works Cited

Furey, Edward "Feet and Inches Calculator" at https://www.calculatorsoup.com/calculators/construction/feetandinches.php from CalculatorSoup, https://www.calculatorsoup.com - Online Calculators, Last updated: November 12, 2018  

Omni Calculator, "Inches to Fraction Calculator", Created by Wojciech Sas, PhD, Last updated: Jun 05, 2023, https://www.omnicalculator.com/conversion/inches-to-fraction.  

Spike, 1 January 2022, "Foot and Inch to Decimal Format Conversion", https://www.spikevm.com/calculators/fraction-decimal-calculators.php.  

\bigskip
\bigskip

# EcoC²S Links

EcoC²S Home -- https://www.ecoccs.com/  
About EcoC²S -- https://www.ecoccs.com/about_ecoc2s.html  
Services -- https://www.ecoccs.com/services.html  
1 Stop Shop -- https://www.ecoccs.com/other_biz.html  
Products -- https://www.questionuniverse.com/products.html  
Media -- https://www.ecoccs.com/media.html  
Resources -- https://www.ecoccs.com/resources.html  
R Trainings and Resources provided by EcoC²S (Irucka Embry, E.I.T.) -- https://www.ecoccs.com/rtraining.html  

\bigskip
\bigskip

# Copyright and License

All R code written by Irucka Embry is distributed under the GPL-3 (or later) license, see the [GNU General Public License {GPL} page](https://www.gnu.org/licenses/gpl-3.0.html).  

All written content originally created by Irucka Embry is copyrighted under the Creative Commons Attribution-ShareAlike 4.0 International License. All other written content retains the copyright of the original author(s).  

This work is licensed under a [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/).  
