Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion episodes/01-introduction-to-high-dimensional-data.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ These data include information collected from the
assay as well as associated metadata from individuals from whom samples were
taken.

```{r libsload}
```{r libsload, message=FALSE}
library("SummarizedExperiment")
methylation <- readRDS("data/methylation.rds")
head(colData(methylation))

Expand Down
5 changes: 4 additions & 1 deletion episodes/02-high-dimensional-regression.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,17 @@ order <- order(age)
age_ord <- age[order]
methyl_mat_ord <- methyl_mat[, order]

## create annotation df with rownames matching columns of methylation matrix
ann_df <- data.frame(age = age_ord, row.names=colnames(methyl_mat_ord))

# plot heatmap
pheatmap(methyl_mat_ord,
cluster_cols = FALSE,
show_rownames = FALSE,
show_colnames = FALSE,
legend_title = "M-value",
main = "Feature vs Sample",
annotation_col = data.frame(age = age_ord))
annotation_col = ann_df)
```

::::::::::::::::::::::::::::::::::::::: challenge
Expand Down
6 changes: 3 additions & 3 deletions episodes/03-regression-regularisation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ data into training and test sets, fit a linear model and calculate the errors. F
calculate the training error. Let's start by splitting the data into training and test sets:

```{r data}
methylation <- readRDS("/data/methylation.rds")
methylation <- readRDS("data/methylation.rds")

library("SummarizedExperiment")
age <- methylation$Age
Expand Down Expand Up @@ -921,13 +921,13 @@ plot_elastic(0.75)
but the paths are a bit less
extreme than with pure LASSO; similar to ridge.
```{r elastic, fig.cap="Line plot showing coefficient values from an elastic net model against L1 norm.", fig.alt="A line plot showing coefficient values from an elastic net model against L1 norm. The coefficients, generally, suddenly become zero as L1 norm decreases. However, some coefficients increase in size before decreasing as L1 norm decreases."}
elastic <- glmnet(methyl_mat[, -1], age, alpha = 0.5)
elastic <- glmnet(methyl_mat, age, alpha = 0.5)
plot(elastic)
```
2. The process of model selection is similar for elastic net models as for
LASSO models.
```{r elastic-cv, fig.cap="A plot of the cross-validation mean squared error of an elastic net model against log lambda."}
elastic_cv <- cv.glmnet(methyl_mat[, -1], age, alpha = 0.5)
elastic_cv <- cv.glmnet(methyl_mat, age, alpha = 0.5)
plot(elastic_cv)
```
3. You can see that the coefficients from these two methods are broadly
Expand Down
5 changes: 4 additions & 1 deletion episodes/07-hierarchical.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ clustering is really useful, and then we can understand how to apply it in more
detail. To do this, we'll return to the large [`methylation`](https://carpentries-incubator.github.io/high-dimensional-stats-r/data/index.html) dataset we worked
with in the regression lessons. Let's load and visually inspect the data:

```{r}
```{r, message=FALSE}
library("SummarizedExperiment")
methyl <- readRDS("data/methylation.rds")

# transpose this Bioconductor dataset to show features in columns
Expand All @@ -110,6 +111,7 @@ appear to have a similar methylation levels across all rows. However, they are
all quite jumbled at the moment, so it's hard to tell how many line up exactly.

```{r heatmap-noclust, echo=FALSE, fig.cap="Heatmap of methylation data.", fig.alt="Heatmap of methylation level with individuals along the y axis and methylation sites along the x axis. Red colours indicate high methylation levels (up to around 4), blue colours indicate low methylation levels (to around -4) and white indicates methylation levels close to zero. There are many vertical blue and red stripes."}
library("pheatmap")
pheatmap(methyl_mat,
legend_title = "Methylation level",
cluster_rows = FALSE,
Expand All @@ -133,6 +135,7 @@ groups features based on dissimilarity (here, Euclidean distance) and orders
rows and columns to show clustering of features and observations.

```{r heatmap-clust, fig.cap="Heatmap of methylation data clustered by methylation sites and individuals.", fig.alt="Heatmap of methylation level with individuals along the y axis and methylation sites along the x axis, clustered by methylation sites and individuals. Red colours indicate high methylation levels (up to around 4), blue colours indicate low methylation levels (to around -4) and white indicates methylation levels close to zero. This time, the individuals and methylation sites are clustered and the plot fades from vertical red lines on the left side to vertical blue lines on the right side. There are two, arguably three, white stripes towards the middle of the plot."}
library("pheatmap")
pheatmap(methyl_mat,
legend_title = "Methylation level",
cluster_rows = TRUE,
Expand Down
107 changes: 96 additions & 11 deletions renv/activate.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
local({

# the requested version of renv
version <- "1.1.5"
version <- "1.1.7"
attr(version, "md5") <- "dd5d60f155dadff4c88c2fc6680504b4"
attr(version, "sha") <- NULL

# the project directory
Expand Down Expand Up @@ -168,6 +169,16 @@ local({
if (quiet)
return(invisible())

# also check for config environment variables that should suppress messages
# https://github.com/rstudio/renv/issues/2214
enabled <- Sys.getenv("RENV_CONFIG_STARTUP_QUIET", unset = NA)
if (!is.na(enabled) && tolower(enabled) %in% c("true", "1"))
return(invisible())

enabled <- Sys.getenv("RENV_CONFIG_SYNCHRONIZED_CHECK", unset = NA)
if (!is.na(enabled) && tolower(enabled) %in% c("false", "0"))
return(invisible())

msg <- sprintf(fmt, ...)
cat(msg, file = stdout(), sep = if (appendLF) "\n" else "")

Expand Down Expand Up @@ -215,6 +226,16 @@ local({
section <- header(sprintf("Bootstrapping renv %s", friendly))
catf(section)

# try to install renv from cache
md5 <- attr(version, "md5", exact = TRUE)
if (length(md5)) {
pkgpath <- renv_bootstrap_find(version)
if (length(pkgpath) && file.exists(pkgpath)) {
file.copy(pkgpath, library, recursive = TRUE)
return(invisible())
}
}

# attempt to download renv
catf("- Downloading renv ... ", appendLF = FALSE)
withCallingHandlers(
Expand All @@ -240,7 +261,6 @@ local({

# add empty line to break up bootstrapping from normal output
catf("")

return(invisible())
}

Expand All @@ -256,14 +276,22 @@ local({
# check for repos override
repos <- Sys.getenv("RENV_CONFIG_REPOS_OVERRIDE", unset = NA)
if (!is.na(repos)) {

# check for RSPM; if set, use a fallback repository for renv
rspm <- Sys.getenv("RSPM", unset = NA)
if (identical(rspm, repos))
repos <- c(RSPM = rspm, CRAN = cran)

return(repos)


# split on ';' if present
parts <- strsplit(repos, ";", fixed = TRUE)[[1L]]

# split into named repositories if present
idx <- regexpr("=", parts, fixed = TRUE)
keys <- substring(parts, 1L, idx - 1L)
vals <- substring(parts, idx + 1L)
names(vals) <- keys

# if we have a single unnamed repository, call it CRAN
if (length(vals) == 1L && identical(keys, ""))
names(vals) <- "CRAN"

return(vals)

}

# check for lockfile repositories
Expand Down Expand Up @@ -511,6 +539,51 @@ local({

}

renv_bootstrap_find <- function(version) {

path <- renv_bootstrap_find_cache(version)
if (length(path) && file.exists(path)) {
catf("- Using renv %s from global package cache", version)
return(path)
}

}

renv_bootstrap_find_cache <- function(version) {

md5 <- attr(version, "md5", exact = TRUE)
if (is.null(md5))
return()

# infer path to renv cache
cache <- Sys.getenv("RENV_PATHS_CACHE", unset = "")
if (!nzchar(cache)) {
root <- Sys.getenv("RENV_PATHS_ROOT", unset = NA)
if (!is.na(root))
cache <- file.path(root, "cache")
}

if (!nzchar(cache)) {
tools <- asNamespace("tools")
if (is.function(tools$R_user_dir)) {
root <- tools$R_user_dir("renv", "cache")
cache <- file.path(root, "cache")
}
}

# start completing path to cache
file.path(
cache,
renv_bootstrap_cache_version(),
renv_bootstrap_platform_prefix(),
"renv",
version,
md5,
"renv"
)

}

renv_bootstrap_download_tarball <- function(version) {

# if the user has provided the path to a tarball via
Expand Down Expand Up @@ -979,7 +1052,7 @@ local({

renv_bootstrap_validate_version_release <- function(version, description) {
expected <- description[["Version"]]
is.character(expected) && identical(expected, version)
is.character(expected) && identical(c(expected), c(version))
}

renv_bootstrap_hash_text <- function(text) {
Expand Down Expand Up @@ -1181,6 +1254,18 @@ local({

}

renv_bootstrap_cache_version <- function() {
# NOTE: users should normally not override the cache version;
# this is provided just to make testing easier
Sys.getenv("RENV_CACHE_VERSION", unset = "v5")
}

renv_bootstrap_cache_version_previous <- function() {
version <- renv_bootstrap_cache_version()
number <- as.integer(substring(version, 2L))
paste("v", number - 1L, sep = "")
}

renv_json_read <- function(file = NULL, text = NULL) {

jlerr <- NULL
Expand Down
Loading