Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get filename from read.csv(file.choose( ))

Tags:

r

I'm wondering if it would be possible to draw out out the filename from a file.choose() command embedded within a read.csv call. Right now I'm doing this in two steps, but the user has to select the same file twice in order to extract both the data (csv) and the filename for use in a function I run. I want to make it so the user only has to select the file once, and then I can use both the data and the name of the file.

Here's what I'm working with:

data <- read.csv(file.choose(), skip=1))
name <- basename(file.choose())

I'm running OS X if that helps, since I think file.choose() has different behavior depending on the OS. Thanks in advance.

like image 428
bosbmgatl Avatar asked Feb 10 '12 19:02

bosbmgatl


1 Answers

Why you use an embedded file.choose() command?

filename <- file.choose()
data <- read.csv(filename, skip=1)
name <- basename(filename)
like image 184
sgibb Avatar answered Sep 23 '22 02:09

sgibb