Home > database >  R targets packages error - Last error: <text>:1:2: unexpected '/'
R targets packages error - Last error: <text>:1:2: unexpected '/'

Time:11-14

When I run the code, there is a error:

✖ error target quantities_plot_base
• end pipeline [3.558 seconds]
Error:

! Error running targets::tar_make()
  
Target errors: targets::tar_meta(fields = error, complete_only = TRUE)
  
Tips: https://books.ropensci.org/targets/debugging.html
  
Last error: <text>:1:2: unexpected '/'

1:  /

     ^

The target is the following code in the list:

tar_target(
    name = quantities_plot_base,
    command = powerscale_seq_summ_plot(sensitivity_sequence_base)
  )

And the powerscale_seq_summ_plot in the function file is like:

powerscale_seq_summ_plot <- function(powerscale_seq) {

  powerscale_plot_quantities(powerscale_seq, variables = "b_wrist", quantities = c("mean", "sd"), mcse = TRUE)  
    ggplot2::facet_wrap(
      . ~ quantity,
      scales = "free",
      ncol = 3,
      labeller = ggplot2::as_labeller(
        c(
          "b_wrist" = "",
          "sd" = "SD",
          "mean" = "Mean",
          "cjs_dist" = "$\\text{CJS}_{\\text{dist}}$"
        )
      )
    )  
    guides(colour = "none")  
    xlab("Power-scaling $\\alpha$")  
    scale_color_manual(values = rep("black", 3))  
    scale_shape_manual(values = c("prior" = 15, "likelihood" = 22), labels = c("Prior power-scaling", "Likelihood power-scaling"), name = NULL)  
    scale_linetype_manual(values = "dashed", labels = "$\\pm2$ MCSE", name = NULL)  
    cowplot::theme_half_open()  
    theme(
      legend.position = "bottom",
      legend.text = element_text(size = 10),
      axis.text = element_text(size = 10),
      axis.title = element_text(size = 10),
      strip.text = element_text(size = 10),
      strip.background = element_blank(),
      legend.text.align = 0,
      axis.line.y = element_blank(),
      axis.ticks.y = element_line(colour = "black"),
      axis.line.x = element_blank(),
      axis.ticks.x = element_line(colour = "black"),
      legend.title = element_text(size = 10),
      aspect.ratio = 1
    )  
    cowplot::panel_border(color = "black", size = 1)
}

enter image description here

Using your function (With b_wrist swapped for mu; I made the variable call another argument in the function).

powerscale_seq_summ_plot(pss, "mu")
# Scale for colour is already present.
# Adding another scale for colour, which will replace the existing scale.
# Scale for shape is already present.
# Adding another scale for shape, which will replace the existing scale.
# Scale for linetype is already present.
# Adding another scale for linetype, which will replace the existing scale. 

enter image description here

I don't know of any libraries that let you use $ encapsulated expressions that ggplot2 will understand. If these work for you, have at it! Otherwise, here are some solutions to the label errors I see in the plot above.

For "cjs_dist" = "$\\text{CJS}_{\\text{dist}}$" I don't know what you're trying to do here. Are you just trying to show "CJS_dist" instead of "cjs_dist"? If so, then be literal: "cjs_dist" = "CJS_dist".

For xlab("Power-scaling $\\alpha$") use xlab(expression(Power-scaling~alpha))

For scale_linetype_manual(values = "dashed", labels = "$\\pm2$ MCSE", name = NULL) replace the labels with "±2 MCSE"

When I made these changes in your UDF (user-defined function) this is what I rendered.

enter image description here

  • Related