Skip to content

Commit fbf8217

Browse files
committed
Add example why caching is better
1 parent e715f84 commit fbf8217

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: SpectraTutorials
22
Title: Mass Spectrometry Data Analysis with Spectra
3-
Version: 0.8.1
3+
Version: 0.8.2
44
Authors@R: c(
55
person(given = "Johannes", family = "Rainer",
66
email = "Johannes.Rainer@eurac.edu",

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Version 0.8
22

3+
## Version 0.8.2
4+
5+
- Add second example why caching changes is better than saving to database.
6+
37
## Version 0.8.1
48

59
- Include feedback and suggestions from Philippine Louail.

vignettes/Spectra-backends.Rmd

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,31 @@ values, are stored (as a new column) in the caching data frame:
632632
s_db@backend@localData |> head()
633633
```
634634

635+
Actually, why do we not want to change the data directly in the database? It
636+
should be fairly simple to add a new column to the database table or change the
637+
values in that. There are actually two reasons to **not** do that: firstly we
638+
don't want to change the *raw* data that might be stored in the database
639+
(e.g. if the database contains reference MS2 spectra, such as in the case of a
640+
`Spectra` with MassBank data) and secondly, we want to avoid the following
641+
situation: imagine we create a copy of our `s_db` variable and change the
642+
retention times in that variable:
643+
644+
```{r}
645+
#' Change values in a copy of the variable
646+
s_db2 <- s_db
647+
rtime(s_db2) <- rtime(s_db2) + 10
648+
```
649+
650+
Writing these changes back to the database would also change the retention time
651+
values in the original `s_db` variable and that is for obvious reasons not
652+
desired.
653+
654+
```{r}
655+
#' Retention times of original copy should NOT change
656+
rtime(s_db) |> head()
657+
rtime(s_db2) |> head()
658+
```
659+
635660
Note that this can also be used for `MsBackendOfflineSql` backends to
636661
cache spectra variables in memory for faster access.
637662

0 commit comments

Comments
 (0)