Getting started with a new R package can be a very tedious business (if not to say annoying). This document was written with the intention to make the first steps as painless as possible.
If you have no idea what a function does and how it works, it is always a good idea to have a closer look into the example sections of the package functions. The package ‘RCarb’ has one central function named model_DoseRate()
. The example given in the example section in the manual will be used in the following to illustrate the central package functionality in three steps.
To get a first impression on how the example dataset looks like, you call the function head()
to print the first five rows of a data.frame
on the terminal.
## SAMP_NAME K K_X T T_X U U_X U238 U238_X U234_U238
## 1 BN107 0.080 0.010 1.64 0.08 1.90 0.08 0 0 0
## 2 BN102 0.170 0.009 2.59 0.03 3.02 0.07 0 0 0
## 3 BN106 0.560 0.030 1.80 0.11 0.83 0.03 0 0 0
## 4 LV61 0.131 0.005 0.85 0.03 0.86 0.11 0 0 0
## 5 LV99 0.047 0.003 0.59 0.03 1.94 0.11 0 0 0
## 6 D101 0.105 0.004 0.65 0.02 1.25 0.08 0 0 0
## U234_U238_X WCI WCI_X WCF WCF_X CC CC_X DIAM DIAM_X COSMIC COSMIC_X
## 1 0 20 7 7 7 62 1 180 10 0.180 0.0100
## 2 0 20 10 10 10 68 1 180 22 0.180 0.0100
## 3 0 20 6 6 6 49 1 145 15 0.180 0.0100
## 4 0 12 5 2 2 17 1 210 30 0.069 0.0035
## 5 0 8 3 5 5 61 3 210 30 0.182 0.0090
## 6 0 8 3 2 2 59 2 210 20 0.180 0.0100
## INTERNAL INTERNAL_X ONSET ONSET_X FINISH FINISH_X DE DE_X
## 1 0 0 100 10 40 10 98 9
## 2 0 0 100 10 40 10 130 10
## 3 0 0 100 10 40 10 120 10
## 4 0 0 120 10 40 10 52 5
## 5 0 0 60 10 40 10 50 4
## 6 0 0 180 10 130 10 81 5
Unfortunately, the naming of the table columns is not straightforward to understand. The good news is that each column carries additional information that can be seen in the R terminal by typing, e.g., for the column ‘K’ (which is the 2nd column):
## $UNIT
## [1] "%"
##
## $DESCRIPTION
## [1] "K concentration"
It reveals that the numbers in the column correspond to the potassium concentration and are given in ‘%’. Similar all other columns can be inspected.
Now we want to start the modelling using the data given for the first sample only.
##extract only the first row
data <- Example_Data[1,]
##run model
results <- model_DoseRate(
data = data,
n.MC = 10,
txtProgressBar = FALSE)
##
## [model_DoseRate()]
##
## Sample ID: BN107
## Equivalent dose: 98 ± 9 Gy
## Diameter: 180 µm
## MC runs error estim.: 10
## ------------------------------------------------
## Age (conv.): 133.451 ± 12.251 ka
## Age (new): 117.443 ± 8.979 ka
##
## Dose rate (conv.): 0.734 ± 0.037 Gy/ka
## Dose rate (onset): 0.936 ± 0.054 Gy/ka
## Dose rate (final): 0.742 ± 0.032 Gy/ka
## ------------------------------------------------
The function returns a terminal output along with two plots, which are mostly similar to the original graphical output provided by the ‘MATLAB’ program ‘Carb’.
Please note: In the example above the function model_DoseRate()
was called with two additional arguments, n.MC = 10
and txtProgressBar = FALSE
. The first argument limits the number of Monte Carlo runs for the error estimation to 10 and the second argument prevents the plotting of the progress bar, indicating the progression of the calculation. Both arguments were solely set to reduce calculation time and output in this vignette.
Obviously, you do not want to run each row in the input table, separately, to model the dose rate for all samples given in the example dataset you can call the model without subsetting the dataset first. Be careful, the calculation may take some time.
Running only the example dataset is somewhat dissatisfactory, and the usual case will be that you provide your own dataset as input. While you can enter all data directly using R, the package offers another way, using external spreadsheet software such as ‘Libre Office’ (or, of course, MS Excel). The procedure is sketched in the following.
The function write_InputTemplate()
was written to create a template table (a CSV-file) that can be subsequently opened and filled. Using the function ensures that your input data have the correct structure, e.g., the correct number for columns and column names.
The path given with the argument file
can be modified as needed.
Own data are added using an external spreadsheet program and then save again as CSV-file.
For re-importing, the data standard R functionality can be used.
The final modelling does not differ from the call already show above (here without a plot output):
##run model
results <- model_DoseRate(
data = data,
n.MC = 10,
txtProgressBar = FALSE,
plot = FALSE)
##
## [model_DoseRate()]
##
## Sample ID: 1
## Equivalent dose: 98 ± 9 Gy
## Diameter: 180 µm
## MC runs error estim.: 10
## ------------------------------------------------
## Age (conv.): 133.451 ± 9.183 ka
## Age (new): 117.443 ± 7.095 ka
##
## Dose rate (conv.): 0.734 ± 0.042 Gy/ka
## Dose rate (onset): 0.985 ± 0.076 Gy/ka
## Dose rate (final): 0.745 ± 0.027 Gy/ka
## ------------------------------------------------