Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
NiceIScoding opened this issue Mar 14, 2024 · 9 comments

Comments

@NiceIScoding
Copy link

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

@NiceIScoding
Copy link
Author

Hi - can anyone help with this?

@DavisVaughan
Copy link
Member

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

@NiceIScoding
Copy link
Author

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?

@DavisVaughan
Copy link
Member

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

@NiceIScoding
Copy link
Author

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

@DavisVaughan
Copy link
Member

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

@NiceIScoding
Copy link
Author

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?

@DavisVaughan
Copy link
Member

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

@NiceIScoding
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants