Search code examples
rconfigrdsgzip

Error in gzfile(file, "rb") : invalid 'description' argument Called from: gzfile(file, "rb")


I have a problem with a function I have made trying to map some columns with config file I have made. I am running the function yet I get the error:

Error in gzfile(file, "rb") : invalid 'description' argument Called        from: gzfile(file, "rb")

I have looked online, including stack overflow and do not get a proper answer to this question. Would you please help? This functions I have made works well on another machine but as I tried to deploy my work onto my personal laptop, it seems I get this error.

This is what I am attempting to do in Mac:

Thinking of the the path is set to this:

 data_import_list <- list(list(data_path = "Users/gb/Rprojects/data/data.csv", 
                               config_path = "Users/gb/Rprojects/lgt-config/inp/"))

And then I read it with the function

import_col_types <- function(config_path){
  column_mapping <- readRDS(file.path(config_path, "column_mapping.rds")) 

  # get list of config files 
  config_file_list <- Sys.glob(paste0(config_path, "*.rds"))
}

Actually this is how I read with the above function:

import_col_types(data_import_list)

Solution

  • Print out file before the error. Check it is what you think it is. I can replicate your error message with:

    > gzfile(1,"rb")
    Error in gzfile(1, "rb") : invalid 'description' argument
    > gzfile(NA,"rb")
    Error in gzfile(NA, "rb") : invalid 'description' argument
    > gzfile(NULL,"rb")
    Error in gzfile(NULL, "rb") : invalid 'description' argument
    

    but not:

    > gzfile("nonexist","rb")
    Error in gzfile("nonexist", "rb") : cannot open the connection
    In addition: Warning message:
    In gzfile("nonexist", "rb") :
      cannot open compressed file 'nonexist', probable reason 'No such file or directory'
    

    so it looks like your file is broken. No way we can see what it is, so you need to debug this yourself. Basic debugging.