emit <- function(key, values) {
cat(key, "=", paste(values, collapse = ","), "\n", sep = "")
}
record <- list("ridge", c(4, 8), 10L, matrix(1:4, 2), list("wet", TRUE),
function(n) n * 2, data.frame(value=6))
names(record) <- c("site", "depth", "count", "cells", "notes", "transform", "table")
emit("construct", c(is.list(record), length(record), names(record), record$transform(3),
is.data.frame(record$table)))
emit("extract", c(typeof(record[3]), typeof(record[[3]]), record[[3]], record$depth,
dim(record[["cells"]]), length(record[["notes"]])))
part <- record[1:3]
part[4] <- list("checked")
added <- part[[4]]
part[4] <- NULL
missing <- part[4]
outside <- tryCatch({part[[4]]; FALSE}, error=function(err) TRUE)
part[[3]] <- 14L
emit("edit", c(added, length(part), part[[3]], length(missing), is.na(names(missing)),
is.null(missing[[1]]), outside))
part["count"] <- list(NULL)
retained <- length(part)
part$count <- NULL
emit("null", c(retained, length(part), length(part[-2L])))
pieces <- list(5L, "east", TRUE)
observed <- character()
for (item in pieces) {
observed <- c(observed, typeof(item))
item <- 0
}
updated <- lapply(pieces, typeof)
emit("traverse", c(observed, unlist(updated), pieces[[1]], typeof(updated)))
left <- list("ridge", 3)
right <- list(TRUE, 12L)
emit("merge", c(typeof(c(3L, 5L)), typeof(c(3L, "ridge")),
typeof(c(left, right)), length(c(left, right)),
length(append(left, right, after=1L)), length(c(left, list(9)))))
flattened <- unlist(list(c(2, 5), list(7, 9)), use.names=FALSE)
mixed <- unlist(list(4, "west"), use.names=FALSE)
emit("flatten", c(flattened, typeof(mixed), unlist(list(c(2,5))) + unlist(list(c(7,9)))))
本例需在 基础 R。已在项目独立的 Windows x64 R 4.6.2 环境验证。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:基础 R。已在项目独立的 Windows x64 R 4.6.2 环境验证。
入口文件:projects/r-list-matrix-array/lists.R
本地运行步骤快速上手
- 点击上方“保存源码”保存为
lists.R,或下载右侧课程工程包。 - 确认本地已准备 基础 R。已在项目独立的 Windows x64 R 4.6.2 环境验证。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联29章) · 含当前章节或实例 · mbskycom202612a317.zip
课程关联工程包(登记关联3章) · 含当前章节或实例 · mbskycom202612a324.zip