Skip to main content

sherlock_io/patterns/
r.rs

1use regex::Regex;
2
3pub struct RPatterns {
4    external_patterns: Vec<Regex>,
5    cache_patterns: Vec<Regex>,
6    extensions: Vec<String>,
7}
8
9impl RPatterns {
10    pub fn new() -> Self {
11        let external_patterns = vec![
12            // R package build artifacts
13            Regex::new(r"\.Rcheck/").unwrap(),
14            Regex::new(r"\.Rhistory").unwrap(),
15            Regex::new(r"\.RData").unwrap(),
16            Regex::new(r"\.Ruserdata").unwrap(),
17            
18            // R session files
19            Regex::new(r"\.Rproj\.user/").unwrap(),
20            Regex::new(r"\.Rapp\.history").unwrap(),
21            
22            // R package files
23            Regex::new(r"\.tar\.gz$").unwrap(),
24            Regex::new(r"\.tgz$").unwrap(),
25            
26            // renv (R environment management)
27            Regex::new(r"renv/").unwrap(),
28            Regex::new(r"renv\.lock").unwrap(),
29            
30            // packrat (legacy R package management)
31            Regex::new(r"packrat/").unwrap(),
32            
33            // R documentation
34            Regex::new(r"\.Rd2pdf").unwrap(),
35            
36            // R cache
37            Regex::new(r"\.cache/").unwrap(),
38            Regex::new(r"cache/").unwrap(),
39            
40            // R Markdown cache
41            Regex::new(r"_cache/").unwrap(),
42            Regex::new(r"[^/]*_cache/").unwrap(),
43            
44            // R output files
45            Regex::new(r"\.out$").unwrap(),
46            Regex::new(r"\.log$").unwrap(),
47            
48            // Shiny app files
49            Regex::new(r"rsconnect/").unwrap(),
50            
51            // R plots
52            Regex::new(r"Rplots\.pdf").unwrap(),
53            
54            // Temporary files
55            Regex::new(r"\.tmp/").unwrap(),
56            Regex::new(r"tmp/").unwrap(),
57            Regex::new(r"\.swp$").unwrap(),
58            Regex::new(r"\.swo$").unwrap(),
59            Regex::new(r"~$").unwrap(),
60            
61            // R specific temp files
62            Regex::new(r"\.bak$").unwrap(),
63            Regex::new(r"\.orig$").unwrap(),
64            
65            // R Studio files
66            Regex::new(r"\.Rproj$").unwrap(),
67            
68            // R build files
69            Regex::new(r"src/\*\.o$").unwrap(),
70            Regex::new(r"src/\*\.so$").unwrap(),
71            Regex::new(r"src/\*\.dll$").unwrap(),
72        ];
73
74        let cache_patterns = vec![
75            // R package cache
76            Regex::new(r"\.Rcheck/").unwrap(),
77            
78            // R session cache
79            Regex::new(r"\.Rproj\.user/").unwrap(),
80            
81            // renv cache
82            Regex::new(r"renv/").unwrap(),
83            
84            // R Markdown cache
85            Regex::new(r"_cache/").unwrap(),
86            
87            // General cache
88            Regex::new(r"\.cache/").unwrap(),
89        ];
90
91        let extensions = vec![
92            // R source files
93            "r".to_string(),
94            "R".to_string(),
95            
96            // R Markdown
97            "rmd".to_string(),
98            "Rmd".to_string(),
99            
100            // R Notebook
101            "rnw".to_string(),
102            "Rnw".to_string(),
103            
104            // R Sweave
105            "rtex".to_string(),
106            "Rtex".to_string(),
107            
108            // R Documentation
109            "rd".to_string(),
110            "Rd".to_string(),
111            
112            // R Data files
113            "rda".to_string(),
114            "RData".to_string(),
115            "rds".to_string(),
116            
117            // Configuration files
118            "yml".to_string(),
119            "yaml".to_string(),
120            "json".to_string(),
121            "toml".to_string(),
122            
123            // Documentation
124            "md".to_string(),
125            "rst".to_string(),
126            "txt".to_string(),
127            
128            // Web files (for Shiny apps)
129            "html".to_string(),
130            "css".to_string(),
131            "js".to_string(),
132            
133            // Data files
134            "csv".to_string(),
135            "tsv".to_string(),
136            "xlsx".to_string(),
137            "json".to_string(),
138            "xml".to_string(),
139            
140            // SQL
141            "sql".to_string(),
142            
143            // Shell scripts
144            "sh".to_string(),
145            "bash".to_string(),
146            
147            // C/C++ (for R packages)
148            "c".to_string(),
149            "cpp".to_string(),
150            "h".to_string(),
151            "hpp".to_string(),
152            
153            // Fortran (for R packages)
154            "f".to_string(),
155            "f90".to_string(),
156            "f95".to_string(),
157        ];
158
159        Self {
160            external_patterns,
161            cache_patterns,
162            extensions,
163        }
164    }
165
166    pub fn get_external_patterns(&self) -> &[Regex] {
167        &self.external_patterns
168    }
169
170    pub fn get_cache_patterns(&self) -> &[Regex] {
171        &self.cache_patterns
172    }
173
174    pub fn get_extensions(&self) -> &[String] {
175        &self.extensions
176    }
177
178    pub fn get_script_names() -> Vec<&'static str> {
179        vec![
180            // R package files
181            "DESCRIPTION", "NAMESPACE", "NEWS", "NEWS.md",
182            "README", "README.md", "README.Rmd",
183            "LICENSE", "LICENCE", "COPYING",
184            
185            // R project files
186            ".Rprofile", ".Renviron", ".Rproj",
187            
188            // renv files
189            "renv.lock", ".Rprofile",
190            
191            // packrat files
192            "packrat.lock", ".Rprofile",
193            
194            // R build files
195            "configure", "configure.ac", "configure.in",
196            "Makefile", "Makefile.in", "Makefile.win",
197            "cleanup", "cleanup.win",
198            
199            // CI/CD
200            ".github/workflows/r.yml",
201            ".github/workflows/R-CMD-check.yaml",
202            ".travis.yml", "appveyor.yml",
203            
204            // Docker
205            "Dockerfile", "docker-compose.yml",
206            
207            // Editor
208            ".editorconfig", ".gitignore",
209            ".Rbuildignore", ".Rinstignore",
210            
211            // Scripts
212            "run.sh", "build.sh", "deploy.sh",
213            "install.sh", "test.sh",
214            
215            // Shiny
216            "app.R", "ui.R", "server.R",
217            "global.R", "www/",
218            
219            // R Markdown
220            "index.Rmd", "_site.yml", "_bookdown.yml",
221            
222            // pkgdown
223            "_pkgdown.yml", "pkgdown.yml",
224        ]
225    }
226
227    pub fn get_common_directories() -> Vec<&'static str> {
228        vec![
229            // R package structure
230            "R/", "man/", "vignettes/", "inst/",
231            "data/", "data-raw/", "exec/",
232            
233            // Tests
234            "tests/", "testthat/",
235            
236            // Documentation
237            "doc/", "docs/", "vignettes/",
238            
239            // Build
240            ".Rcheck/", "src/",
241            
242            // Dependencies
243            "renv/", "packrat/",
244            
245            // Shiny
246            "www/", "R/", "data/",
247            
248            // R Markdown
249            "_site/", "_book/", "_bookdown_files/",
250            
251            // Configuration
252            "config/", "conf/",
253            
254            // Logs
255            "logs/", "log/",
256            
257            // Output
258            "output/", "results/", "figures/",
259            
260            // Tools
261            "tools/", "scripts/",
262            
263            // Resources
264            "resources/", "assets/",
265        ]
266    }
267}