1

I've got this problem: Read only certain columns from xls

I want to comment on this answer by @R.Prost but I don't have enough reputation:

df <- read_xlsx(path = "filename.xls", sheet = "sheetname", range = cell_cols("A:G"))

This answer specifies the range "A:G" which includes all columns from A to G. I want to select non-adjacent columns only, e.g. only columns A, C and G. I've tried:

 df <- read_xlsx(path = "filename.xls", sheet = "sheetname", range = cell_cols(c("A","C","G")))

But no joy, this still reads in A thru G.

I feel like this should be really simple and that I'm doing something silly. How do I read in only A, C and G?

zx8754
  • 52,746
  • 12
  • 114
  • 209
B_Real
  • 177
  • 2
  • 12
  • 2
    Maybe read all columns, then subset within R? – zx8754 Sep 13 '18 at 10:09
  • Thanks @zx8754 :-) Different package seems cleaner, so: `df <- read.xlsx(path = "filename.xls", sheet = "sheetname", cols = (c(1,3,5))) ` Although this uses column numbers instead of letters ("A" etc) ... but it does the trick. – B_Real Sep 13 '18 at 11:33
  • 1
    I submitted an issue at [GitHub](https://github.com/rsheets/cellranger/issues/33), it must an easy fix, or it already exists and we just don't know how to use it :) – zx8754 Sep 13 '18 at 11:53
  • 2
    It's documented by `?cellranger::cell_cols`, "Note it is not possible to request non-contiguous columns". Responses to similar issues have stated that there are long-term plans to support column selection in a similar way to the readr package, but until then I don't think this is possible. – nacnudus Sep 13 '18 at 11:58

0 Answers0