-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckCranMirrors.qmd
More file actions
47 lines (39 loc) · 1.1 KB
/
checkCranMirrors.qmd
File metadata and controls
47 lines (39 loc) · 1.1 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
---
title: "Check Available CRAN Mirrors"
author: "Habib Ezzatabadi Pour"
format: gfm
date: "`r format(Sys.Date(), '%Y-%m-%d')`"
output: github_document
---
```{r}
# List of selected CRAN mirrors to check
mirrors <- c(
Iran = "https://cran.um.ac.ir",
Turkey = "https://cran.pau.edu.tr",
UAE = "https://cran.nyuad.nyu.edu",
Global = "https://cloud.r-project.org"
)
# Function to test connection and measure response time
check_mirror_status <- function(url) {
start <- Sys.time()
result <- tryCatch({
readLines(url, n = 1)
list(status = "Available",
latency = round(difftime(Sys.time(), start, units = "secs"), 3))
}, error = function(e) {
list(status = "Unavailable", latency = NA)
})
return(result)
}
# Apply to all mirrors and collect results
results <- lapply(mirrors, check_mirror_status)
# Convert to data frame
df_status <- data.frame(
Mirror = names(mirrors),
URL = unname(mirrors),
Status = sapply(results, `[[`, "status"),
ResponseSec = sapply(results, `[[`, "latency")
)
# Print result table
print(df_status, row.names = FALSE)
```