Hello everyone, i'm new to R programming and dendrochronology. I'm trying to calculate correlations between monthly precipitation averages and tree growth (tree ring data) using the dcc function. the problem is, I'm getting an error message: Error in is.finite(if (is.character(from)) from <- as.numeric(from) else from) :
default method not implemented for type 'list', and I don't know what it means. Can someone advise on both the meaning and the solution?
library(dplR)
library(treeclim)
library("TRADER")
library(utils)
library(ggplot2)
library(graphics)
# set working directory
setwd("F:/Obby/PhD/untitled folder/Dendrochronology/R scripts/For correlations/2800_Abies")
# AF28OFINAL
# read in measurements
chaf28o6 <- read.rwl("chaf28o6.rwl")
#
rwl.report(chaf28o6)
#
plot(chaf28o6, plot.type="spag")
# detrending all the series in the chaf2806 at once
chaf28o6.rwl <- detrend(rwl = chaf28o6, method = "Friedman")
#descriptive statistics
rwl.stats(chaf28o6[1:17])
#Building a Mean Value Chronology
chaf28o6.crn <- chron(chaf28o6.rwl, prefix = "CAM")
library(readr)
clim <- read_csv("Abies2800.csv")
View(clim)
#tractating the chronology data from (1884-2019) to (1950-2019)
a = (1:136)
b = as.data.frame(a)
b
c = cbind(b, chaf28o6.crn)
d.crn = chaf28o6.crn[c(67:136), ]
##response function analysis in treeclim - modeled after Dendroclim2002.
##Can take dynamic = "static", "moving", "evolving"
resp <- dcc(chrono = d.crn, climate = clim, selection = 1:10,
method = "correlation", dynamic = "static", win_size = 35, win_offset = 1, start_last = TRUE,
timespan = NULL, var_names = NULL, ci = 0.05, boot = "std", sb = FALSE)
If you are new to R I can imagine that you meet some problems on your way.
From your post I see that somewhere (?) a list is passed where a vector is expected.
See the example below that gives a similar error.
So how to solve this?
Check at which point the error occurs.
See if there are any warnings before that point: these could point to the actual problem.
You use two input files: do they look alright (similar to previous ones if the code was run before) ?
Because we don't have your data, we can not reproduce your error.
Maybe it is possible to provide a small example of the two files so that we can have a look?
See e.g. How to do a minimal reproducible example .
In saying this I assume that the packages dplR, treeclim and TRADER (that are unknown to me) are publicly available. If they are not needed in this part of the code remove them in your post to create 'minimal reproducible examples'.
Success with your project!
# this will work
from = c('1',"2")
if (is.character(from)) from <- as.numeric(from) else from
print(from)
#> [1] 1 2
is.finite(from)
#> [1] TRUE TRUE
#this will work
from = c(1,2)
if (is.character(from)) from <- as.numeric(from) else from
#> [1] 1 2
print(from)
#> [1] 1 2
is.finite(from)
#> [1] TRUE TRUE
#this will not work
from = list('1',"2")
if (is.character(from)) from <- as.numeric(from) else from
#> [[1]]
#> [1] "1"
#>
#> [[2]]
#> [1] "2"
print(from)
#> [[1]]
#> [1] "1"
#>
#> [[2]]
#> [1] "2"
is.finite(from)
#> Error in is.finite(from): default method not implemented for type 'list'
#this will not work
from = list(1,1)
if (is.character(from)) from <- as.numeric(from) else from
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 1
print(from)
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 1
is.finite(from)
#> Error in is.finite(from): default method not implemented for type 'list'
Created on 2021-11-29 by the reprex package (v2.0.0)