cschwarz-stat-sfu-ca / BTSPAS

Bayesian Time Stratified Petersen Analysis System
1 stars 3 forks source link

Critical error under R 4.0.2 #26

Closed ErikSuring closed 3 years ago

ErikSuring commented 3 years ago

Using R 4.0.2 BTSPAS will sometime work, sometimes not with our data.

This example works under R 3.5 but will error out under R 4.0:

library("BTSPAS")

input.title <- "YaquinaMill Coho Smolt 2017"
input.prefix <- "YaquinaMill Coho Smolt 2017"
input.jweek <- c(9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25)
input.n1 <- c(6,   7,  12,   6,  40,  14,  34,  36,  77,  40,  46, 109,  36,  92,  38,  34,  12)
input.m2 <- c(1,  1,  3,  1, 17,  3,  5,  8, 15,  7, 11, 23,  9, 43, 27, 27, 12)
input.u2 <- c(9,   9,  13,  14,  38,  12,  33,  39, 157,  41,  66, 129,  51,  83,  40,  33,   8)
input.sampfrac <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)

    output.tspde <- TimeStratPetersenDiagError_fit(
                       title=input.title,
                       prefix=input.prefix,
                       time=input.jweek,
                       n1=input.n1, 
                       m2=input.m2, 
                       u2=input.u2,
                       sampfrac=input.sampfrac,
                       debug=TRUE
                       )

The error is:

    Error: Cannot create zero-length unit vector ("unit" subsetting)

    > traceback()
    15: stop("Cannot create zero-length unit vector (\"unit\" subsetting)", 
             call. = FALSE)
    14: `[.unit`(table$widths, strip_cols)
    13: table$widths[strip_cols]
    12: f(...)
    11: self$facet$draw_panels(panels, self$layout, self$panel_scales_x, 
                               self$panel_scales_y, self$panel_params, self$coord, data, 
                               theme, self$facet_params)
    10: f(..., self = self)
    9: layout$render(geom_grobs, data, theme, plot$labels)
    8: ggplot_gtable.ggplot_built(data)
    7: ggplot_gtable(data)
    6: plot.ggplot(x)
    5: plot(x)
    4: .fun(piece, ...)
    3: do.ply(i)
    2: l_ply(trace.plot, function(x) {
      plot(x)
    })
    1: TimeStratPetersenDiagError_fit(title = input.title, prefix = input.prefix, 
                                      time = input.jweek, n1 = input.n1, m2 = input.m2, u2 = input.u2, 
                                      sampfrac = input.sampfrac, debug = TRUE)
cschwarz-stat-sfu-ca commented 3 years ago

Thanks Eric... someone else reported this problem as well. The cause is that facet_wrap_paginate "hangs" when the final page does not have a full complement of plots. For example, suppose there are 15 sample times. THe traceplots are plotted in 2x2 arrays and so would need 4 pages. But the last page only has 3 plots.

The development version of BTSPAS has this fixed. I was planning to resubmit to CRAN this weekend with the bugfix, but you can download the development version from devtools::install_github("cschwarz-stat-sfu-ca/BTSPAS", dependencies = TRUE, build_vignettes = TRUE)

Carl

On Fri, Sep 4, 2020 at 4:27 PM ErikSuring notifications@github.com wrote:

Using R 4.0.2 BTSPAS will sometime work, sometimes not with our data.

This example works under R 3.5 but will error out under R 4.0:

library("BTSPAS")

input.title <- "YaquinaMill Coho Smolt 2017" input.prefix <- "YaquinaMill Coho Smolt 2017" input.jweek <- c(9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25) input.n1 <- c(6, 7, 12, 6, 40, 14, 34, 36, 77, 40, 46, 109, 36, 92, 38, 34, 12) input.m2 <- c(1, 1, 3, 1, 17, 3, 5, 8, 15, 7, 11, 23, 9, 43, 27, 27, 12) input.u2 <- c(9, 9, 13, 14, 38, 12, 33, 39, 157, 41, 66, 129, 51, 83, 40, 33, 8) input.sampfrac <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)

output.tspde <- TimeStratPetersenDiagError_fit( title=input.title, prefix=input.prefix, time=input.jweek, n1=input.n1, m2=input.m2, u2=input.u2, sampfrac=input.sampfrac, debug=TRUE )

The error is:

Error: Cannot create zero-length unit vector ("unit" subsetting)

traceback() 15: stop("Cannot create zero-length unit vector (\"unit\" subsetting)", call. = FALSE) 14: [.unit(table$widths, strip_cols) 13: table$widths[strip_cols] 12: f(...) 11: self$facet$draw_panels(panels, self$layout, self$panel_scales_x, self$panel_scales_y, self$panel_params, self$coord, data, theme, self$facet_params) 10: f(..., self = self) 9: layout$render(geom_grobs, data, theme, plot$labels) 8: ggplot_gtable.ggplot_built(data) 7: ggplot_gtable(data) 6: plot.ggplot(x) 5: plot(x) 4: .fun(piece, ...) 3: do.ply(i) 2: l_ply(trace.plot, function(x) { plot(x) }) 1: TimeStratPetersenDiagError_fit(title = input.title, prefix = input.prefix, time = input.jweek, n1 = input.n1, m2 = input.m2, u2 = input.u2, sampfrac = input.sampfrac, debug = TRUE)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cschwarz-stat-sfu-ca/BTSPAS/issues/26, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABXIXRUXU5D3DNU7AI575XDSEFZULANCNFSM4QZUNQCQ .

ErikSuring commented 3 years ago

Thanks, Version 2020.9.1 works in R 4.0.

I do get some notes in the console for every run now, though:

Initializing model

  |++++++++++++++++++++++++++++++++++++++++++++++++++| 100%
  |**************************************************| 100%

*** Finished JAGS ***

geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?

 ***** FILES and GRAPHS saved in 
cschwarz-stat-sfu-ca commented 3 years ago

An unfortunately side-effect of my fix for the bug in facet_wrap_paginate. What happens is that I create "dummy" plots to fill the final page with a single observation and ggplot say you can't join a single plot with a line (geom_line) and gives the warning message. You can't say "group=1" because this will affect the other plots....Unfortunately, I don't know how to turn off these warning messages from ggplot2.

If you are using RMarkdown, you can suppress the warning message, e.g.

...

Another solution may be to use

https://stackoverflow.com/questions/13286531/how-to-suppress-warnings-when-plotting-with-ggplot but the problem isn't in my code so I don't want to try and "fix" the facet_wrap_paginate code.

Sorry. Carl.

On Mon, Sep 21, 2020 at 4:55 PM ErikSuring notifications@github.com wrote:

Thanks, Version 2020.9.1 works in R 4.0.

I do get some notes in the console for every run now, though:

Initializing model

|++++++++++++++++++++++++++++++++++++++++++++++++++| 100% |**| 100%

Finished JAGS geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?

***** FILES and GRAPHS saved in

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cschwarz-stat-sfu-ca/BTSPAS/issues/26#issuecomment-696441337, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABXIXRRFO532VR6HN7WJ54TSG7RYBANCNFSM4QZUNQCQ .

ErikSuring commented 3 years ago

Thanks,