Specifying Column Types when Importing xlsx Data to R with Package readxl

后端 未结 6 1505
梦如初夏
梦如初夏 2020-12-13 07:40

I\'m importing xlsx 2007 tables into R 3.2.1patched using package readxl 0.1.0 under Windows 7 64. The tables\' size is

6条回答
  •  鱼传尺愫
    2020-12-13 07:47

    Reading the source, it looks like column types are guessed by the functions xls_col_types or xlsx_col_types, which are implemented in Rcpp, but have the defaults:

    xls_col_types <- function(path, na, sheet = 0L, nskip = 0L, n = 100L, has_col_names = FALSE) {
        .Call('readxl_xls_col_types', PACKAGE = 'readxl', path, na, sheet, nskip, n, has_col_names)
    }
    
    xlsx_col_types <- function(path, sheet = 0L, na = "", nskip = 0L, n = 100L) {
        .Call('readxl_xlsx_col_types', PACKAGE = 'readxl', path, sheet, na, nskip, n)
    }
    

    My C++ is very rusty, but it looks like the n=100L is the command telling how many rows to read.

    As these are non exported functions, paste in:

    fixInNamespace("xls_col_types", "readxl")
    fixInNamespace("xlsx_col_types", "readxl")
    

    And in the pop-up, change the n = 100L to a larger number. Then rerun your file import.

提交回复
热议问题