Skip to content

Commit 434c7d9

Browse files
committed
cli-gen >> {sessioncheck}; geo-sptemp >> vario eq; reg-other >> {ZeroOnedists}; vis-gen >> fraunces ex
1 parent 764043e commit 434c7d9

5 files changed

Lines changed: 85 additions & 33 deletions

File tree

qmd/cli-general.qmd

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,29 @@
4444

4545
- Misc
4646

47+
- Packages
48+
49+
- [{]{style="color: #990000"}[fs](https://fs.r-lib.org/){style="color: #990000"}[}]{style="color: #990000"} - A cross-platform, uniform interface to file system operations
50+
- Navarro deep dive, [For fs](https://blog.djnavarro.net/posts/2024-10-06_fs/)
51+
- [{]{style="color: #990000"}[littler](https://eddelbuettel.github.io/littler/){style="color: #990000"}[}]{style="color: #990000"} - A scripting and command-line front-end for GNU R
52+
- [{]{style="color: #990000"}[ps](https://ps.r-lib.org/index.html){style="color: #990000"}[}]{style="color: #990000"} - List, Query, Manipulate System Processes
53+
- [{]{style="color: #990000"}[rapp](https://github.com/r-lib/Rapp){style="color: #990000"}[}]{style="color: #990000"} - Package for building a polished CLI application from a simple R script
54+
- An alternative front end to R, a drop-in replacement for Rscript that automatically parses command line arguments into R values
55+
- [{]{style="color: #990000"}[seekr](https://cran.r-project.org/web/packages/seekr/index.html){style="color: #990000"}[}]{style="color: #990000"} - Recursively list files from a directory, filter them using a regular expression, read their contents, and extract lines that match a user-defined pattern
56+
- Designed for quick code base exploration, log inspection, or any use case involving pattern-based file and line filtering.
57+
- [{]{style="color: #990000"}[sessioncheck](https://sessioncheck.djnavarro.net/){style="color: #990000"}[}]{style="color: #990000"} - Provides simple tools that can be called at the top of a script, and produce warnings or errors if it detects signs that the script is not being executed in a clean R session.
58+
- The intended user for sessioncheck is a beginner or intermediate level R user who needs a drop-in replacement for the simple but unsafe method of calling `rm(list = ls())` at the top of the script
59+
- Gaining the habit of restarting the R session is best when iterating or running a new script, but I guess beginning level programmers don't do this.
60+
- The only thing that `rm(list = ls())` does is remove *objects* from the global environment. This gives the user the false sense of confidence that their R session is "clean," even although in most cases it is sufficient
61+
- e.g. doesn't remove attached packages
62+
- [{]{style="color: #990000"}[sys](https://jeroen.r-universe.dev/sys){style="color: #990000"}[}]{style="color: #990000"} - Offers drop-in replacements for the `system2` with fine control and consistent behavior across platforms
63+
- Supports clean interruption, timeout, background tasks, and streaming STDIN / STDOUT / STDERR over binary or text connections.
64+
- Arguments on Windows automatically get encoded and quoted to work on different locales.
65+
66+
- Resources
67+
68+
- [Invoking R from the command line](https://colinfay.me/intro-to-r/appendix-b-invoking-r.html) for using `R` and `R CMD`
69+
4770
- The "shebang" line starting `#!` allows a script to be run directly from the command line without explicitly passing it through `Rscript` or `r`. It's not required but is a helpful convenience on Unix-like systems.
4871

4972
``` r
@@ -82,24 +105,6 @@
82105
3. Inside folder add a batch script to launch R with --no-save arg
83106
4. Add folder to path
84107

85-
- Resources
86-
87-
- [Invoking R from the command line](https://colinfay.me/intro-to-r/appendix-b-invoking-r.html) for using `R` and `R CMD`
88-
89-
- Packages
90-
91-
- [{]{style="color: #990000"}[ps](https://ps.r-lib.org/index.html){style="color: #990000"}[}]{style="color: #990000"} - List, Query, Manipulate System Processes
92-
- [{]{style="color: #990000"}[fs](https://fs.r-lib.org/){style="color: #990000"}[}]{style="color: #990000"} - A cross-platform, uniform interface to file system operations
93-
- Navarro deep dive, [For fs](https://blog.djnavarro.net/posts/2024-10-06_fs/)
94-
- [{]{style="color: #990000"}[littler](https://eddelbuettel.github.io/littler/){style="color: #990000"}[}]{style="color: #990000"} - A scripting and command-line front-end for GNU R
95-
- [{]{style="color: #990000"}[rapp](https://github.com/r-lib/Rapp){style="color: #990000"}[}]{style="color: #990000"} - Package for building a polished CLI application from a simple R script
96-
- An alternative front end to R, a drop-in replacement for Rscript that automatically parses command line arguments into R values
97-
- [{]{style="color: #990000"}[sys](https://jeroen.r-universe.dev/sys){style="color: #990000"}[}]{style="color: #990000"} - Offers drop-in replacements for the `system2` with fine control and consistent behavior across platforms
98-
- Supports clean interruption, timeout, background tasks, and streaming STDIN / STDOUT / STDERR over binary or text connections.
99-
- Arguments on Windows automatically get encoded and quoted to work on different locales.
100-
- [{]{style="color: #990000"}[seekr](https://cran.r-project.org/web/packages/seekr/index.html){style="color: #990000"}[}]{style="color: #990000"} - Recursively list files from a directory, filter them using a regular expression, read their contents, and extract lines that match a user-defined pattern
101-
- Designed for quick code base exploration, log inspection, or any use case involving pattern-based file and line filtering.
102-
103108
- File Paths
104109

105110
- Various functions to make file paths easier to work with ([source](https://bsky.app/profile/randvegan.bsky.social/post/3lllsqh33b22p))
@@ -357,7 +362,7 @@
357362
- Linux utilities through Python in CLI\
358363
359364
| Command | Purpose | More |
360-
|----|----|----|
365+
|------------------------|------------------------|------------------------|
361366
| `python3.12 -m uuid` | Like `uuidgen` CLI utility | [Docs](https://docs.python.org/3/library/uuid.html#command-line-usage) |
362367
| `python3.12 -m sqlite3` | Like `sqlite3` CLI utility | [Docs](https://docs.python.org/3/library/sqlite3.html#command-line-interface) |
363368
| `python -m zipfile` | Like `zip` & `unzip` CLI utilities | [Docs](https://docs.python.org/3/library/zipfile.html#command-line-interface) |
@@ -375,7 +380,7 @@
375380
- Code Utilities\
376381
377382
| Command | Purpose | More |
378-
|----|----|----|
383+
|------------------------|------------------------|------------------------|
379384
| `python -m pip` | Install third-party Python packages | [Docs](https://docs.python.org/3/installing/index.html) |
380385
| `python -m venv` | Create a virtual environment | [Docs](https://docs.python.org/3/library/venv.html) |
381386
| `python -m pdb` | Run the Python Debugger | [Docs](https://docs.python.org/3/library/pdb.html) |

qmd/geospatial-spat-temp.qmd

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
- Notes from
5151
- [spacetime: Spatio-Temporal Data in R](https://cran.r-project.org/web/packages/spacetime/vignettes/jss816.pdf) - It's been superceded by [{stars}]{style="color: #990000"}, but there didn't seem to be much about working with vector data in [{stars}]{style="color: #990000"} vignettes. So, it seemed like a better place to start for a beginner, and I think the concepts might transfer since the packages were created by the same people. Some packages still use sp and spacetime, so it could be useful in using with those packages
5252
- [Spatio-Temporal Interpolation using gstat](https://cran.r-project.org/web/packages/gstat/vignettes/spatio-temporal-kriging.pdf)
53+
- [Spatio-Temporal Kriging in R](https://www.r-bloggers.com/2015/08/spatio-temporal-kriging-in-r/)
54+
- Also shows how to create a prediction grid of roads
5355
- Recommended Workflow ([source](https://www.youtube.com/watch?v=P18CZinoKos&list=WL&index=2))
5456
- Go from simple analysis to complex (analysis) to get a feel for your data first. A lot of times, you probably will not need to do a spatio-temporal analysis at all.
5557
- Steps
@@ -1660,6 +1662,14 @@
16601662
16611663
### Variogram {#sec-geo-sptemp-krig-var .unnumbered}
16621664
1665+
#### Description
1666+
1667+
- Sample (or Empirical) Spatio-Temporal Variogram (Sherman 2011)\
1668+
$$
1669+
\hat \gamma(h,u) = \frac{1}{2N(h,u)} \sum_{N(h,u)} (Z(s_i, t_i) - Z(s_j, t_j))^2
1670+
$$
1671+
- Calculates the semi-variance for every pair of points separated by distance $h$ and time $u$.
1672+
16631673
#### `variogramST` {#sec-geo-sptemp-krig-var-vst .unnumbered}
16641674
16651675
- [Docs](https://cran.r-project.org/web/packages/gstat/refman/gstat.html#variogramST)
@@ -1670,6 +1680,7 @@
16701680
- Default: The length of the diagonal of the box spanning the data is divided by three.
16711681
- [tlags]{.arg-text} - Time lags to consider. Default is [0:15]{.arg-text}
16721682
- For [STIDF]{.arg-text} data, the argument [tunit]{.arg-text} is recommended (and only used in the case of STIDF) to set the temporal unit of the [tlags]{.arg-text}.
1683+
- I think [tunit]{.arg-text} has the same type of input as `difftime` which are ["secs"]{.arg-text}, ["mins"]{.arg-text}, ["hours"]{.arg-text}, ["days"]{.arg-text}, or ["weeks"]{.arg-text}
16731684
- The number of time lags is multiplied by the number of spatial bins to get the total bins. So the fewer the better, if the situation allows it. Fewer might also reduce computation time.
16741685
- Seems like days are typical time unit is spatio-temporal data, so 15 lags might be a lot depending on what's being measured.
16751686
- Using the ACFs to get an idea
@@ -1866,8 +1877,6 @@
18661877
- Reducing tlags is a variance-control decision, not a bias decision
18671878
- heatmap also shows little correlation (high variance) approaching lag 5 while spatial correlation remains pretty strong even at 200 km (see stat ninja video)
18681879
- From [post](https://www.r-bloggers.com/2015/08/spatio-temporal-kriging-in-r/)
1869-
- For some reason the first model, generic separable model gets automatically discarded even though it has the lowest error.
1870-
18711880
- Empircal variogram heatmap
18721881
18731882
``` r

qmd/r-snippets.qmd

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,22 +128,31 @@
128128

129129
- See Lewis's [Recode NA](https://cghlewis.github.io/data-wrangling-functions/recode-values/recode-na.html) tutorial for other options
130130
131-
- dataframes
131+
- Remove rows with *any* NAs
132132
133-
``` r
134-
df %>% na.omit
135-
df %>% filter(complete.cases(.))
136-
df %>% tidyr::drop_na()
137-
```
133+
- Dataframes
134+
135+
``` r
136+
df %>% na.omit
137+
df %>% filter(complete.cases(.))
138+
df %>% tidyr::drop_na()
139+
```
140+
141+
- Variables
142+
143+
``` r
144+
df %>% filter(!is.na(x1))
145+
df %>% tidyr::drop_na(x1)
146+
```
138147
139-
- variables
148+
- Remove rows will *all* NAs
140149
141150
``` r
142-
df %>% filter(!is.na(x1))
143-
df %>% tidyr::drop_na(x1)
151+
df |> filter(!if_all(everything(), is.na))
152+
df |> filter_out(if_all(everything(), is.na))
144153
```
145154
146-
- Replace NAs with 0 for certain columns
155+
- Replace NAs with 0 for certain columns (or the entire tibble w/`everything()`)
147156
148157
``` r
149158
d18 %>%
@@ -833,6 +842,15 @@
833842

834843
as.POSIXct(num_datetime, origin = "1970-01-01", tz = "UTC")
835844
#> [1] "2026-02-19 10:35:00 UTC"
845+
846+
# lop off milliseconds when included (13 digits)
847+
as.POSIXlt(as.numeric(
848+
# paste converts to string
849+
substr(paste(data$generation_time[1]),
850+
start = 1,
851+
stop = 10)),
852+
origin = "1970-01-01")
853+
#> [1] "2011-10-14 11:14:46 CEST"
836854
```
837855

838856
- The previous month and its year ([source](https://hachyderm.io/@jimgar/113408078964321237))
@@ -851,6 +869,24 @@
851869
format(seq(Sys.Date(), length = 2, by = "-1 month")[2], "%B %Y")
852870
```
853871

872+
- Subsetting
873+
874+
- Base
875+
876+
``` r
877+
# rows
878+
sub_data <-
879+
data[data$TIME >= as.POSIXct('2011-12-12 00:00 CET') &
880+
data$TIME <= as.POSIXct('2011-12-14 23:00 CET'), ]
881+
882+
# columns
883+
# dates is a vector of dates in same order as the columns of air
884+
keep_cols <- dates >= as.Date("2005-01-01") &
885+
dates <= as.Date("2010-12-31")
886+
887+
air_sub <- air[, keep_cols]
888+
```
889+
854890
- Intervals
855891

856892
- Difference between dates

qmd/regression-other.qmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
- Beta Regression
5050
- [{]{style="color: #990000"}[gkwreg](https://cran.r-project.org/web/packages/gkwreg/index.html){style="color: #990000"}[}]{style="color: #990000"} - Implements regression models for bounded continuous data in the open interval (0,1) using the five-parameter Generalized Kumaraswamy distribution
5151
- [{]{style="color: #990000"}[SelectBoost.beta](https://cran.r-project.org/web/packages/SelectBoost.beta/index.html){style="color: #990000"}[}]{style="color: #990000"} - Stability-Selection via Correlated Resampling for Beta-Regression Models
52+
- [{]{style="color: #990000"}[ZeroOneDists](https://cran.r-project.org/web/packages/ZeroOneDists/index.html){style="color: #990000"}[}]{style="color: #990000"} - Zero-one statistical distributions for estimating parameters and fitting regression models within the GAMLSS framework
5253
- Outcome with 0s and 1s
5354
- Extended support Beta Regression (Zeileis), aka XBX Regression
5455
- [Thread](https://fosstodon.org/@zeileis/113146182718858220), [Paper](https://www.zeileis.org/news/xbx/), [{]{style="color: #990000"}[betareg](https://cran.r-project.org/web//packages/betareg/index.html){style="color: #990000"}[}]{style="color: #990000"}

qmd/visualization-general.qmd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,11 @@
314314
- Interesting Gs
315315
- [Fraunces](https://fonts.google.com/specimen/Fraunces)
316316
- Header
317+
- The bold 400 is really thick and interesting as a title
317318
- Stylistic Serif
318319
- Letters: It's got some funky slants to ends of some letters. It's like it takes one curvy segment of a letter and straightens it into a slant. The f and j add an interesting sort of squiggliness or distortion to the font like looking through water.
319320
- Numbers are very cool, especially 2:5. They have the flare of someone with nice penmenship.
320-
- [Example](https://kazuyanagimoto.com/blog/2025/0426_research_workflow/), [Example](https://ecogambler.netlify.app/blog/plant-community-dirichlet/) (w/Commissioner)
321+
- [Example](https://kazuyanagimoto.com/blog/2025/0426_research_workflow/), [Example](https://ecogambler.netlify.app/blog/plant-community-dirichlet/) (w/Commissioner), [Example](https://skills.amditis.tech/interview-transcription/) (w/Plus Jakarta Sans)
321322
- IBM Plex Serif
322323
- Body
323324
- [Bruno Rodrigues' site](https://brodrigues.co/posts/2025-03-20-announcing_rixpress.html)

0 commit comments

Comments
 (0)