OpenDendro / dplR

This is the dev site for the dplR package in R
38 stars 14 forks source link

redfit small issues is.numeric(x) is not TRUE and Error in match.fun #9

Closed chrisdane closed 1 year ago

chrisdane commented 2 years ago

Hi

Two small things (dplR version 1.7.2). The last line of the redfit example

data(cana157)
yrs <- time(cana157)
x <- cana157[, 1]
redf.x <- redfit(x, nsim = 1000)

yields the error

Error in redfit(x, nsim = 1000) : is.numeric(x) is not TRUE

Instead, it must be

redf.x <- redfit(x$TTRSTD, nsim = 1000)

In addition, the very similar call

redf.x <- dplR::redfit(x$TTRSTD, nsim = 1000)

yields the error

Error in match.fun(as.list(cl)[[1]]) : 
  'as.list(dplR::redfit(x = x$TTRSTD, nsim = 1000))[[1]]' is not a function, character or symbol

Cheers, Chris

AndyBunn commented 2 years ago

Hi Chris. That example is set to not run because of time considerations when checking the library. But, it runs fine for me and that's what I'd expect since cana157[, 1] is cana157$TTRSTD (e.g., all(cana157[,1]==cana157$TTRSTD)). Can you confirm that this doesn't run and give me the output from sessionInfo() as well? Thx, A

library(dplR)
data(cana157)
all(cana157[,1]==cana157$TTRSTD)
x <- cana157[, 1]
redf.x <- redfit(x, nsim = 1000)
chrisdane commented 2 years ago

Ouh jeah it works also for me. I probably made a copy-paste mistake or whatever, sorry for this.

But the second error really is there :D

AndyBunn commented 2 years ago

Interesting. So this throws the error.

x <- rnorm(cumsum(100))
redf.x <- dplR::redfit(x)

But this doesn't

library(dplR)
redf.x <- redfit(x)

My initial guess is something to do with the NAMESPACE. I'll look into it when I get the chance. Thx.

AndyBunn commented 1 year ago

Think this is fixed in the dev version.

japhir commented 8 months ago

I'm still getting the same error message after installing the dev version with remote::install_github(). But I also get it after library(dplR) if I leave the function call as dplR::redfit rather than redfit.

EDIT: to make it reproducible:

# no library
data(cana157, package = "dplR")
dplR::redfit(cana157$TTRSTD)
#> Error in match.fun(as.list(cl)[[1]]) : 
#>  'as.list(dplR::redfit(x = cana157$TTRSTD))[[1]]' is not a function, character or symbol

library(dplR)
#> This is dplR version 1.7.7.
#> dplR is part of openDendro https://opendendro.org.
#> New users can visit https://opendendro.github.io/dplR-workshop/ to get started.

dplR::redfit(cana157$TTRSTD)
#> Error in match.fun(as.list(cl)[[1]]) : 
#>  'as.list(dplR::redfit(x = cana157$TTRSTD))[[1]]' is not a function, character or symbol

redfit(cana157$TTRSTD)
#> redfit() in dplR version 1.7.7
#> 
#> Input:
#> ------
#> ofac = 4
#> hifac = 1
#> n50 = 3
#> iwin = 2
#> nsim = 1000
#> 
#> Initial values:
#> ---------------
#> Data variance (from data spectrum) = 0.02679094
#> Avg. dt = 1
#> 
#> Results:
#> --------
#> Avg. autocorr. coeff., rho = 0.5233948
#> Avg. tau = 1.544594
#> Degrees of freedom = 5.785714
#> 6-dB Bandwidth = 0.00862069
#> Critical false-alarm level (Thomson, 1990) = 99.56897
#>    ==> corresponding scaling factor for red noise = 3.203169
#> 
#> Equality of theoretical and data spectrum: Runs test
#> ----------------------------------------------------
#> Test requires iwin = 0
#> Test requires ofac = 1
#> Test requires n50 = 1