R
에 대용량 기능이있는 경우 (예 : 기능이 wavelets
패키지 인 경우) 모든 것을 복사하여 콘솔에 붙여 넣을 수 없습니다. 오류 메시지가 표시됩니다. 그러나 청크로 청크를 복사하면 작동합니다.거대한 기능을 복사하여 붙여 넣는 것이 작동하지 않는 이유
- 왜 이런 일이 발생합니까?
- 이 솔루션은 무엇입니까 (스크립트에 함수를 복사하고로드하지 않고).
R
본체를 사용하고 있습니다. 그것은 약 100 줄에 대해 잘 붙여 넣기 다음 두 번째 줄마다 Error: unexpected...
을 표시하기 시작할 것입니다.
plot.modwt <- function (x, levels = NULL, draw.boundary = FALSE, type = "stack",
col.plot = "black", col.boundary = "red", X.xtick.at = NULL,
X.ytick.at = NULL, Stack.xtick.at = NULL, Stack.ytick.at = NULL,
X.xlab = "t", y.rlabs = TRUE, plot.X = TRUE, plot.W = TRUE,
plot.V = TRUE, ...)
{
stackplot.modwt <- function(x, w.range, v.range, col.plot,
col.boundary, draw.boundary, X.xtick.at, X.ytick.at,
Stack.xtick.at, Stack.ytick.at, X.xlab = "t", plot.X = TRUE) {
innerplot <- function(x, y, type = "l", xtick.at, ytick.at) {
if (is.null(xtick.at) == FALSE || is.null(ytick.at) ==
FALSE) {
plot(x, y, type = "l", axes = FALSE, frame.plot = TRUE)
if (is.null(xtick.at) == FALSE) {
axis(1, at = axTicks(1, xtick.at))
xtickrate <- xtick.at
}
else {
axis(1)
xtickrate <- par("xaxp")
}
if (is.null(ytick.at) == FALSE) {
axis(2, at = axTicks(2, ytick.at))
ytickrate <- ytick.at
}
else {
axis(2)
ytickrate <- par("yaxp")
}
}
else {
plot(x, y, type = "l")
xtickrate <- par("xaxp")
ytickrate <- par("yaxp")
}
tickrate <- list(xtick = xtickrate, ytick = ytickrate)
tickrate
}
if (plot.X) {
nf <- layout(matrix(c(2, 2, 1, 1), 2, 2, byrow = TRUE),
c(1, 2), c(2, 1), TRUE)
par(mai = c(0.6, 0.4, 0.1, 0.6))
if ([email protected] == "ts" || [email protected] == "mts") {
x.range <- [email protected]$tsp[1]:[email protected]$tsp[2]
}
else {
x.range <- 1:dim([email protected])[1]
}
tickrate <- innerplot(x.range, [email protected][, 1], type = "l",
X.xtick.at, X.ytick.at)
right.usrplotrange <- par()$usr[2] - par()$usr[1]
NDCplotrange <- par()$plt[2] - par()$plt[1]
marginpos <- (1 - par()$plt[2])/2
right.usrlabelpos <- ((marginpos * right.usrplotrange)/NDCplotrange) +
par()$usr[2]
text(right.usrlabelpos, 0, "X", xpd = TRUE)
mtext(X.xlab, side = 1, line = 2)
par(mai = c(0, 0.4, 0.1, 0.6))
}
if (plot.X == FALSE) {
par(mai = c(0.4, 0.4, 0.1, 0.6))
if (is.null(Stack.xtick.at) == FALSE) {
xtickrate <- Stack.xtick.at
}
else {
xtickrate <- NULL
}
if (is.null(Stack.ytick.at) == FALSE) {
ytickrate <- Stack.ytick.at
}
else {
ytickrate <- NULL
}
tickrate <- list(xtick = xtickrate, ytick = ytickrate)
}
if (is.null(w.range) == FALSE) {
gammawave = wt.filter.shift([email protected], w.range, wavelet = TRUE,
modwt = TRUE)
}
if (is.null(v.range) == FALSE) {
gammascale = wt.filter.shift([email protected], v.range, wavelet = FALSE,
modwt = TRUE)
}
if (y.rlabs) {
rightlabels <- labels.modwt(w.range = w.range, v.range = v.range,
gammah = gammawave, gammag = gammascale)
}
else {
rightlabels <- NULL
}
if (draw.boundary) {
matrixlist <- list(modwt = as.matrix.modwt(x, w.range,
v.range), posbound = boundary.as.matrix.modwt(x,
w.range, v.range, positive = TRUE), negbound = boundary.as.matrix.modwt(x,
w.range, v.range, positive = FALSE))
col <- c(col.plot, col.boundary, col.boundary)
stackplot(matrixlist, y = NULL, y.rlabs = rightlabels,
type = c("l", "h", "h"), col = col, xtick.at = tickrate$xtick,
ytick.at = tickrate$ytick)
}
else {
matrixlist <- list(modwt = as.matrix.modwt(x, w.range,
v.range))
col <- col.plot
stackplot(matrixlist, y = NULL, y.rlabs = rightlabels,
type = "l", col = col, xtick.at = tickrate$xtick,
ytick.at = tickrate$ytick)
}
}
boundary.as.matrix.modwt <- function(x, w.range, v.range,
positive = TRUE) {
if (is.null(w.range) == FALSE) {
wavecoefmatrix <- array(NA, c(2 * dim([email protected])[1],
length(w.range)))
Wjplot <- rep(NA, 2 * dim([email protected])[1])
wavecoefmatrix.index <- 0
W.Ljs <- ((2^w.range) - 1) * ([email protected]@L - 1) + 1
for (j in w.range) {
wavecoefmatrix.index <- wavecoefmatrix.index +
1
if (positive) {
boundaryheight <- max([email protected][[j]])
}
else {
boundaryheight <- min([email protected][[j]])
}
leftspace <- rep(NA, 2 * (W.Ljs[wavecoefmatrix.index] -
2 - vjH.modwt([email protected]@L, j, dim([email protected])[1])) -
1)
rightspace <- rep(NA, 2 * (vjH.modwt([email protected]@L,
j, dim([email protected])[1])))
middlespace <- rep(NA, 2 * dim([email protected])[1] -
2 - length(leftspace) - length(rightspace))
Wjplot <- c(leftspace, boundaryheight, middlespace,
boundaryheight, rightspace)
wavecoefmatrix[, wavecoefmatrix.index] <- Wjplot
}
rownames(wavecoefmatrix) <- seq(0.5, dim([email protected])[1],
by = 0.5)
}
if (is.null(v.range) == FALSE) {
scalecoefmatrix <- array(NA, c(2 * dim([email protected])[1],
length(v.range)))
Vjplot <- rep(NA, 2 * dim([email protected])[1])
scalecoefmatrix.index <- 0
V.Ljs <- ((2^v.range) - 1) * ([email protected]@L - 1) + 1
for (j in v.range) {
scalecoefmatrix.index <- scalecoefmatrix.index +
1
Vj <- [email protected][[j]][, 1] - mean([email protected][[j]][, 1])
if (positive) {
boundaryheight <- max(Vj)
}
else {
boundaryheight <- min(Vj)
}
leftspace <- rep(NA, 2 * (V.Ljs[scalecoefmatrix.index] -
2 - vjG.modwt([email protected]@L, j, dim([email protected])[1])) -
1)
rightspace <- rep(NA, 2 * (vjG.modwt([email protected]@L,
j, dim([email protected])[1])))
middlespace <- rep(NA, 2 * dim([email protected])[1] -
2 - length(leftspace) - length(rightspace))
Vjplot <- c(leftspace, boundaryheight, middlespace,
boundaryheight, rightspace)
scalecoefmatrix[, scalecoefmatrix.index] <- Vjplot
}
rownames(scalecoefmatrix) <- seq(0.5, dim([email protected])[1],
by = 0.5)
}
if (is.null(w.range) == FALSE && is.null(v.range) ==
FALSE) {
results <- cbind(wavecoefmatrix, scalecoefmatrix)
}
if (is.null(w.range) == FALSE && is.null(v.range)) {
results <- wavecoefmatrix
}
if (is.null(w.range) && is.null(v.range) == FALSE) {
results <- scalecoefmatrix
}
results
}
as.matrix.modwt <- function(x, w.range, v.range) {
if (is.null(w.range) == FALSE) {
wavecoefmatrix <- array(NA, c(dim([email protected])[1], length(w.range)))
wavecoefmatrix.index <- 0
for (j in w.range) {
wavecoefmatrix.index <- wavecoefmatrix.index +
1
Wjplot <- [email protected][[j]][, 1]
Wjplot <- levelshift.modwt(Wjplot, wt.filter.shift([email protected],
j, wavelet = TRUE, modwt = TRUE))
wavecoefmatrix[, wavecoefmatrix.index] <- Wjplot
}
rownames(wavecoefmatrix) <- 1:dim([email protected])[1]
}
if (is.null(v.range) == FALSE) {
scalecoefmatrix <- array(NA, c(dim([email protected])[1],
length(v.range)))
scalecoefmatrix.index <- 0
for (k in v.range) {
scalecoefmatrix.index <- scalecoefmatrix.index +
1
Vjplot <- [email protected][[k]][, 1] - mean([email protected][[k]][, 1])
Vjplot <- levelshift.modwt(Vjplot, wt.filter.shift([email protected],
k, wavelet = FALSE, modwt = TRUE))
scalecoefmatrix[, scalecoefmatrix.index] <- Vjplot
}
rownames(scalecoefmatrix) <- 1:dim([email protected])[1]
}
if (is.null(w.range) == FALSE && is.null(v.range) ==
FALSE) {
results <- cbind(wavecoefmatrix, scalecoefmatrix)
}
if (is.null(w.range) == FALSE && is.null(v.range)) {
results <- wavecoefmatrix
}
if (is.null(w.range) && is.null(v.range) == FALSE) {
results <- scalecoefmatrix
}
results
}
labels.modwt <- function(w.range = NULL, v.range = NULL,
gammah = NULL, gammag = NULL) {
verticallabel <- list()
if (is.null(w.range) == FALSE && is.null(gammah) == FALSE) {
for (j in 1:length(w.range)) {
label <- substitute(paste(T^-gamma, W[level]),
list(gamma = gammah[j], level = w.range[j]))
verticallabel <- c(verticallabel, label)
}
}
if (is.null(v.range) == FALSE && is.null(gammag) == FALSE) {
for (i in 1:length(v.range)) {
label <- substitute(paste(T^-gamma, V[level]),
list(gamma = gammag[i], level = v.range[i]))
verticallabel <- c(verticallabel, label)
}
}
results <- verticallabel
results
}
levelshift.modwt <- function(level, shift) {
if (shift != 0) {
level <- c(level[(shift + 1):length(level)], level[1:shift])
}
level
}
shift.modwt <- function(L, j, N) {
Lj <- ((2^j) - 1) * (L - 1) + 1
shift <- min(Lj - 2, N - 1)
shift
}
vjH.modwt <- function(L, j, N) {
Lj <- ((2^j) - 1) * (L - 1) + 1
if (L == 10 || L == 18) {
vjH <- (-Lj/2) + 1
}
else if (L == 14) {
vjH <- (-Lj/2) - 1
}
else {
vjH <- -Lj/2
}
vjH <- abs(vjH)
}
vjG.modwt <- function(L, j, N) {
Lj <- ((2^j) - 1) * (L - 1) + 1
if (L == 10 || L == 18) {
vjG <- -((Lj - 1) * L)/(2 * (L - 1))
}
else if (L == 14) {
vjG <- -((Lj - 1) * (L - 4))/(2 * (L - 1))
}
else {
vjG <- -((Lj - 1) * (L - 2))/(2 * (L - 1))
}
vjG <- abs(vjG)
vjG
}
if (type == "stack") {
if (class(x) != "modwt") {
stop("Invalid argument: 'modwt' object must be of class modwt.")
}
if (is.null(levels)) {
w.range <- 1:[email protected]
v.range <- max(w.range)
}
if (class(levels) == "numeric") {
if (length(levels) == 1) {
w.range <- 1:levels
v.range <- max(w.range)
}
else {
w.range <- levels
v.range <- max(w.range)
}
}
if (class(levels) == "list") {
if (length(levels) < 1) {
w.range <- 1:[email protected]
v.range <- max(w.range)
}
if (length(levels) == 1) {
w.range <- levels[[1]]
v.range <- max(w.range)
}
else {
w.range <- levels[[1]]
v.range <- levels[[2]]
}
}
if (class(levels) != "list" && class(levels) != "vector" &&
class(levels) != "numeric" && is.null(levels) ==
FALSE) {
stop("Invalid argument: 'levels' must be numeric, vector, or list.")
}
if (plot.W == FALSE) {
w.range <- NULL
}
if (plot.V == FALSE) {
v.range <- NULL
}
if (plot.W == FALSE && plot.V == FALSE) {
stop("At least one of plot.W or plot.V must be TRUE")
}
if (is.null(w.range) == FALSE) {
if (min(w.range) < 1 || [email protected] < max(w.range)) {
stop("Invalid argument: elements of 'levels' must be compatible with the level of decomposition of the 'modwt' object.")
}
}
if (is.null(v.range) == FALSE) {
if (min(v.range) < 1 || [email protected] < max(v.range)) {
stop("Invalid argument: elements of 'levels' must be compatible with the level of decomposition of the 'modwt' object.")
}
}
stackplot.modwt(x, w.range, v.range, col.plot, col.boundary,
draw.boundary = draw.boundary, X.xtick.at = X.xtick.at,
X.ytick.at = X.ytick.at, Stack.xtick.at = Stack.xtick.at,
Stack.ytick.at = Stack.ytick.at, X.xlab = X.xlab,
plot.X = plot.X)
}
else {
stop("Only the stackplot is currently implemented.")
}
}
<environment: namespace:wavelets>
재현 가능한 예를주세요. 다음을 제공하십시오 : 1. 복사하여 붙이려는 기능 2.받은 오류 메시지 3. 여기에 복사/붙여 넣기 위치에 대한 정보가 있습니다. RStudio 또는 R 콘솔을 사용하고 있습니까? – Rguy
스크립트 파일에 함수를 저장하고'source()'it ... 편집하고 실행하는 것이 훨씬 실용적입니다. – juba
@juba 내가 복사하여 붙여 넣으려는 질문에 지정했습니다 .... – user2763361