-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.qmd
More file actions
executable file
·109 lines (86 loc) · 3.19 KB
/
objects.qmd
File metadata and controls
executable file
·109 lines (86 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
title: "The results"
format:
html:
include-in-header: Extras/copy-all-code.html
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
echo = TRUE,
eval = FALSE
)
```
```{r}
#| label: setup
#| echo: false
#| eval: true
#| message: false
library(Pmetrics)
library(gt)
r_help <- function(pkg, name, fn = NULL) {
if(is.null(fn)) {fn <- name}
glue::glue("[`{name}`](https://rdrr.io/pkg/{pkg}/man/{fn}.html)")
}
gh_help <- function(name) {
glue::glue("[`{name}`](https://lapkb.github.io/Pmetrics/reference/{name}.html)")
}
pmetrics <- function(){
knitr::asis_output("[Pmetrics]{style=\"color: #841010; font-family: 'Arial', Arial, sans-serif; font-weight: 900;\"}")
}
custom_table <- function(tab){
tab2 <- read.csv(file.path("Data", tab), na.strings = ".") %>% dplyr::mutate(Comments = stringr::str_replace_all(
Comments,
"`([^$`]+)`", # capture any run of non-backtick chars
gh_help("\\1")
))
md <- stringr::str_detect(tab2$Comments, "`.+`")
tab3 <- tab2 %>% gt() %>%
gt::fmt_markdown(columns = Comments, rows = md) %>%
gt::tab_style(
style = list(
cell_fill(color = "black"),
cell_text(color = "white", weight = "bold")
),
locations = cells_column_labels(everything())
)
return(tab3)
}
```
## PM_result details
After a successful NPAG/NPOD run, an R datafile is saved in the /outputs subdirectory of the newly created numerically ordered folder in the working directory. This file is called "PMout.Rdata". These data files can be loaded by ensuring that the Runs folder is set as the working directory or using the `path` argument to `$fit()`, and then using the `r pmetrics()` command `r gh_help("PM_load")`.
There are several data objects contained within the Rdata files which are loaded, making these objects available for plotting and other analysis. This is in contrast to the Legacy method of loading objects into your global R environment, suffixed with the run number, e.g., "op.1" or "final.1". Obscurely loading objects into memory is not good or current programming practice.
Therefore, in R6 `r pmetrics()`, `PM_load()` returns a `r gh_help("PM_result")`object. The fields in the object are in the table below.
```{r}
#| echo: false
#| eval: true
#| results: asis
#| label: obj_table_fields
custom_table("PM_result_fields.csv")
```
To access the fields in a `PM_result` object, use the "$".
```{r}
#| label: obj_access
# load the results of run1
run1 <- PM_load(1, path = "Runs")
run1$op # observed vs. predicted PM_op R6 object
run1$op$time # times in PM_op
run1$op$data # this accesses the whole observed vs. predicted raw data frame
```
Most of the fields are themselves R6 objects with methods. We'll dive into this in more detail in the next chapter.
```{r}
#| label: obj_methods
# summarize observed vs. predicted data
run1$op$summary()
# plot it
run1$op$plot()
```
The `PM_result` object itself also contains several methods in addition to the R6 objects in fields. The table below lists these methods (functions) and their descriptions.
```{r}
#| echo: false
#| eval: true
#| results: asis
#| label: obj_table_methods
custom_table("PM_result_methods.csv")
```