trouble specifying colmuns to read

80 views
Skip to first unread message

Kirk Wythers

unread,
Apr 17, 2015, 1:00:26 PM4/17/15
to r-packa...@googlegroups.com
I am trying to extract a particular block of data from an excel work book. So far I have gotten the basic form of read.xlsx to work and can specify startRow and endRow. However, I am struggling to get the readColumn functionality working. 

I can see how the example apporaches the prob by reading into "file", loading the workbook into "wb", then spcifiying which sheet with "sheets" and "sheet". However I can not seem to the first line"

file <- system.file("path_to_folder", "excel_file.xls", package = "xlsx")

to work properly. On my machine the command runs with out an error, but only placed two " into the object "file"

I end up with 

> file
[1] "" 

which is an empty object. The next command 

wb <- loadWorkbook(file)

throws an error "Error in loadWorkbook(file) : Cannot find"

which makes sense, since there is noting in the object "file" 

Any suggestings would be much appreciated.

Adrian Dragulescu

unread,
Apr 18, 2015, 10:18:46 PM4/18/15
to R-package-xlsx
Kirk, 

The file is the actual path to your file on the disk, e.g.  file <- "C:/temp/myfile.xlsx" on a Windows system. 

Best, 
Adrian

--
You received this message because you are subscribed to the Google Groups "R-package-xlsx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to r-package-xls...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kirk Wythers

unread,
Apr 20, 2015, 8:56:34 AM4/20/15
to r-packa...@googlegroups.com
Thanks for the reply Adrian. Can you clarify the three arguments then in the example:

file <- system.file("tests", "test_import.xlsx", package = "xlsx"), I guess I'm uncear as to what system.file() does in this case. 

if my file is located in: 

~/projects/south_watetershead.xls

Should the command simply be:

file <- system.file("~/projects/shouth_watershead.xls") 

However, I tried that and still get an empty object  "'  

Again, thanks for your work on this package, and thank you for the extra advice.

Best,
Kirk

Adrian Dragulescu

unread,
Apr 20, 2015, 7:48:17 PM4/20/15
to R-package-xlsx
Kirk, 

On Linux, you should use the full path, don't assume that the ~ will expand. 

wb <- loadWorkbook("/home/kirk/watershed.xls")

and continue from there. 

Adrian

PS. Specifying your sessionInfo() helps me doing less guessing.
system.file is only useful to find files "inside" a package -- good for testing, but it's not your use case.  Your file is not inside the xlsx package folder.  
 

Reply all
Reply to author
Forward
0 new messages