tidyr icon indicating copy to clipboard operation
tidyr copied to clipboard

Error in tidyr package & issue with columns being added to Markdown output where used to put into rows (no change to code)

Open NICE-DN opened this issue 1 year ago • 9 comments

Have had this error message saying to log this here

Error in df_append(): ! after must be a whole number, not an integer NA. This is an internal error that was detected in the tidyr package. Please report it at https://github.com/tidyverse/tidyr/issues with a reprex (https://tidyverse.org/help/) and the full backtrace. Backtrace:

  1. ... %>% pull(text_row)
  2. tidyr:::unite.data.frame(...)
  3. tidyr:::df_append(after = after) Execution halted

I came across this error when I have been trying to sort out an issue affecting one of our codes where the output is putting some of the output into columns (as per report(1) document)

report (1).docx

We have not changed the code (attached below) from the time when it was putting the output into rows as we wanted

code.docx

We cant work out why this is happening as one of our colleagues is able to make it work in the usual way (one of his outputs from today is in report(51) document) - is there a problem with a package update?

report (51).doc.docx

NICE-DN avatar Mar 14 '24 11:03 NICE-DN

Hi - can anyone help with this?

NICE-DN avatar Mar 21 '24 15:03 NICE-DN

Could you please turn this into a self-contained reprex (short for minimal reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page.

You can install reprex by running (you may already have it, though, if you have the tidyverse package installed):

install.packages("reprex")

Thanks

DavisVaughan avatar Mar 21 '24 15:03 DavisVaughan

Hi, how does creating a reprex work when to recreate their is an app code that calls in a Markdown code? Would it help if I attached the app code and our test input CSV?

NICE-DN avatar Mar 25 '24 15:03 NICE-DN

Ideally you'd post the app code, with any necessary library calls at the top, and with the test data frame inlined into the code as well (or at least a small subset of the data frame that still reproduces the problem). Essentially I'd like to be able to run the code block that you post from top to bottom with 0 changes and have it reproduce the error on my machine as well.

If you can't seem to get a minimal data frame, posting the app code and CSV is ok too as long as I just have to change the file path in the code to import from

DavisVaughan avatar Mar 26 '24 12:03 DavisVaughan

Okay thanks

The app code contained within this document - appcode.docx

pulls in the code as per the attached code.docx document above and applies it to a csv such as the one attached below

ctg-studies.csv

But as per the outputs attached earlier, there seems to be an issue with the latest version of tidyr (as it suggested as much in the render console) putting our format into columns which we have not coded for (and which still appears to be fine when using earlier version of tidyr.

Appreciate any help you can give

NICE-DN avatar Mar 26 '24 12:03 NICE-DN

I was expecting you to actually put that code here in a github comment, rather than attaching a word document with it, like this:

library(shiny)
library(shinydashboard)
library(tidyverse)
library(lubridate)
library(here)
library(spsComps)
library(kableExtra) 

body <- dashboardBody(
  fluidRow(
    box(title = "Clinicaltrials.gov", width = 4, solidHeader = TRUE, 
        fileInput(inputId = "inputfile", "", multiple = FALSE, accept = c("text/csv", "text/comma-separated-values,text/plain", ".csv")) %>% 
          bsPopover("click browse to upload .csv file", "then click download button"),
        p(),
        p(),
        downloadButton("report"), 
        
    )
  )
)


ui <- dashboardPage(
  dashboardHeader(title = "Trial converter"),
  dashboardSidebar(disable = TRUE),
  body
)


server <- function(input, output) {
  
  output$report <- downloadHandler(
    
    filename = "report.doc",
    content = function(file) {
      tempReport <- file.path(tempdir(), "CTcode.Rmd")
      file.copy("CTcode.Rmd", tempReport, overwrite = TRUE)
      params <- list(report.data = input$inputfile$datapath)
      rendered_report <- rmarkdown::render(
        tempReport,
        output_file = file,
        params = params,
        envir = new.env(parent = globalenv())
      )
      
      file.copy(rendered_report, file)
    }
  )
}

shinyApp(ui, server)

Regardless, I don't see any usage of tidyr in this, so I don't see how this could be a tidyr issue

DavisVaughan avatar Mar 26 '24 13:03 DavisVaughan

Okay, although it did say

Error in df_append(): ! after must be a whole number, not an integer NA. This is an internal error that was detected in the tidyr package. Please report it at https://github.com/tidyverse/tidyr/issues with a reprex (https://tidyverse.org/help/) and the full backtrace. Backtrace:

... %>% pull(text_row) tidyr:::unite.data.frame(...) tidyr:::df_append(after = after) Execution halted

  • so what should I do now? Can you see the difference in the outputs - do you have any thoughts on what might be happening to cause that to happen as we have made no changes?

NICE-DN avatar Mar 26 '24 14:03 NICE-DN

Where is your code that calls unite() or pull(text_row)? That's where the problem seems to be

DavisVaughan avatar Mar 26 '24 14:03 DavisVaughan

I'm a bit of a novice truth be told, I'm not sure what you mean? Is there something I need to add?

A bit confused as like I say my colleague can make the code work as it is while some of us cannot.

NICE-DN avatar Mar 26 '24 15:03 NICE-DN

I'm convinced this is https://github.com/tidyverse/tidyr/issues/1548

DavisVaughan avatar Jul 27 '24 13:07 DavisVaughan