R version 4.4.0 alpha (2024-04-05 r86350 ucrt) Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(CodeDepends) > # Simple but with a code block that is stand-alone/unrelated. > p <- readScript(system.file("samples", "dual.R", package = "CodeDepends")) > ## need formulaInputs=TRUE because there is an lm(y~x) call in there ... > > ethread = getExpressionThread("fit", p, formulaInputs = TRUE) > stopifnot(length(ethread) == 3) > > dthread = getDependsThread("fit", getInputs(p, formulaInputs=TRUE)) > stopifnot(identical(dthread, c(1L, 2L, 4L))) > # With redefintions of variables > s <- readScript(system.file("samples", "sitepairs.R", package = "CodeDepends")) > getExpressionThread("covs", s) An object of class "Script" [[1]] mdata <- .readRDS("monitor-data/monitor-subset.rds") [[2]] mdata$LATITUDE <- NULL [[3]] mdata$LONGITUDE <- NULL [[4]] spmdata <- split(mdata, mdata$SITEPOC) [[5]] index.names <- names(spmdata) [[6]] all.dates <- seq(as.Date("2000-01-01"), as.Date("2006-12-31"), "day") [[7]] dateDF <- data.frame(DATE = all.dates) [[8]] pollutants <- c("SULFATE", "NITRATE", "silicon", "Elemental_Carbon", "OC_K14", "Sodium_Ion", "AMMONIUM") [[9]] ad <- lapply(spmdata, function(x) { m <- merge(dateDF, x, by = "DATE", all.x = TRUE) data.matrix(m[, pollutants]) }) [[10]] adata <- array(dim = c(dim(ad[[1]]), length(ad))) [[11]] for (i in seq_along(ad)) { adata[, , i] <- ad[[i]] } [[12]] dimnames(adata) <- list(as.character(all.dates), pollutants, index.names) [[13]] sitedata <- .readRDS("monitor-data/sitedata.rds") [[14]] row.names(sitedata) <- sitedata$SITEPOC [[15]] sitepairs <- as.matrix(expand.grid(sitedata$SITEPOC, sitedata$SITEPOC)) [[16]] colnames(sitepairs) <- c("site1", "site2") [[17]] repeats <- sitepairs[, 1] == sitepairs[, 2] [[18]] sitepairs <- sitepairs[!repeats, ] [[19]] key <- apply(sitepairs, 1, function(x) paste(sort(x), collapse = "")) [[20]] sitepairs <- sitepairs[!duplicated(key), ] [[21]] sitepairs <- as.data.frame(sitepairs, stringsAsFactors = FALSE) [[22]] dist <- apply(sitepairs, 1, function(x) { s1 <- sitedata[x["site1"], ] s2 <- sitedata[x["site2"], ] yd <- (s1$LATITUDE - s2$LATITUDE) * 69.2 xd <- (s1$LONGITUDE - s2$LONGITUDE) * 69.2 * 0.78 sqrt(xd^2 + yd^2) }) [[23]] sitepairs$distance <- dist [[24]] covs <- t(mapply(function(site1, site2) { cc <- cov(adata[, , site1], adata[, , site2], use = "pairwise") diag(cc) }, sitepairs[, 1], sitepairs[, 2])) [[25]] colnames(covs) <- paste(colnames(covs), "c", sep = ".") [[26]] rownames(covs) <- NULL Slot "location": [1] "D:/RCompile/CRANincoming/R-devel/lib/CodeDepends/samples/sitepairs.R" > getDependsThread("covs", as(s, "ScriptInfo")) [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 27 28 [26] 36 > > # With redefintions of variables > p <- readScript(system.file("samples", "results-multi.R", package = "CodeDepends")) > getExpressionThread("results", p) An object of class "Script" [[1]] outcome <- commandArgs(trailingOnly = TRUE)[1] [[2]] specdata <- .readRDS("SpecData-combined.rds") [[3]] pollutants <- c("SULFATE", "NITRATE", "silicon", "Elemental_Carbon", "OC_K14", "Sodium_Ion") [[4]] spec.terms <- list(lag0 = pollutants, lag1 = paste("Lag(", pollutants, ", 1)"), lag2 = paste("Lag(", pollutants, ", 2)")) [[5]] fipsList <- readLines("speciation-fips.txt") [[6]] ranges <- dget("data-ranges.R") [[7]] results <- lapply(spec.terms, function(sterms) { sterms <- sapply(parse(text = sterms), deparse, width.cutoff = 100) cat(sterms, "\n") cycleCounties(fipsList, specdata, sterms, outcome, type = "multiple", ranges = ranges) }) [[8]] pollutants <- spec.terms[[1]] [[9]] results <- lapply(results, function(lag) { colnames(lag$beta) <- pollutants lag }) Slot "location": [1] "D:/RCompile/CRANincoming/R-devel/lib/CodeDepends/samples/results-multi.R" > getDependsThread("results", as(p, "ScriptInfo")) [1] 1 3 7 8 9 10 12 13 14 > > > > > proc.time() user system elapsed 1.00 0.09 1.06