Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is generating the error 'Can't subset `.data` outside of a data mask context' with 'dplyr'?

Tags:

r

dplyr

I have a huge shiny app which uses a huge package. I'm not the author of any of them and I'm a bit lost. A function (fermentationPlot) throws the error: Can't subset .data outside of a data mask context:

Warning: Error in fermentationPlot: Can't subset `.data` outside of a data mask context.
  185: <Anonymous>
  173: dplyr::arrange
  172: dplyr::mutate
  171: as.data.frame

What could be the cause of this error? What does it mean? Below is the code block which generates it. I googled this error message and I found that it can be fixed by downgrading 'dplyr'. I tried 1.0.10, 1.0.5 and 1.0.0, and the error always occurs.

  plotInfo <- dplyr::left_join(
    x = dplyr::select(
      plotDefaults, -c(.data$templateName, .data$minValue, .data$maxValue)
    ), 
    y = plotSettings, 
    by = .data$dataName
  ) %>%
    dplyr::arrange(!is.na(.data$order), -.data$order) %>%
    dplyr::mutate(
      color = replace(.data$color, .data$color == "Blue", "Dark blue"),
      minValue = as.numeric(.data$minValue),
      maxValue = as.numeric(.data$maxValue)
    ) %>%
    as.data.frame()
like image 798
Stéphane Laurent Avatar asked Sep 12 '25 14:09

Stéphane Laurent


1 Answers

The by argument of left_join must be a character vector of column names. Probably the author wanted to do

by = "dataName"

and not

by = .data$dataName
like image 151
Stéphane Laurent Avatar answered Sep 14 '25 04:09

Stéphane Laurent