[R] How to import an excel data file

Richard O'Keefe r@oknz @end|ng |rom gm@||@com
Sat Sep 23 12:07:17 CEST 2023


Are you sure that read.csv() can't read your data?
[If you depend on extra packages you might want to consider using
 the 'groundhog' package so that you can be more confident of
 reproducing your work in a year or two.]

You said that your question is how you should write the name of
the file in your call to read.<whatever>.

> ?read.csv
...
file      the name of the file which the data are to be read from.
          ... If it
          does not contain an _absolute_ path, the file name is
          _relative_ to the current working directory, 'getwd()'.
          Tilde-expansion is performed where supported.

"Tilde-expansion" refers to a common UNIX convention of replacing
~/ at the beginning of a file name by $HOME/ where $HOME is your
home directory, and ~bongiwe/ by $HERS/ where $HERS holds the
absolute name of user bongiwe's home directory.  This is actually
a shell convention, not an operating system kernel convention, but
R is telling us "I can do that too".  So for example to refer to
one of my data files I might do
   jan17 <- read.csv("~/Data/Weather/2017-Jan.dat")
"DFPfiles/ae/FriendsMonroe/KurtzData.csv" is NOT the location of
the file on your system.  It is PART of the location.  We can be
sure of that because it does not begin with a slash.  So it is not
an absolute file name.  There is some value $DIR such that
$DIR is an absolute file name and it names a directory and
"$DIR/DFPfiles/ae/FriendsMonroe/KurtzData.csv" really IS the location of
the file on your system.

If the current working directory is
(1) $DIR/DFPfiles/ae/FriendsMonroe/   use "KurtzData.csv"
(2) $DIR/DFPfiles/ae/     use "FriendsMonroe/KurtzData.csv"
(3) $DIR/DFPfiles    use "ae/FriendsMonroe/KurtzData.csv"
(4) $DIR   use "DFPfiles/ae/FriendsMonroe/KurtzData.csv"
(5) $DIR/DFPfiles/ae/FriendsMonroe/SubDir use "../KurtzData.csv"
I suspect that $DIR may be your home directory, in which case
you can substitute ~ for $DIR.

Of course the file argument can be anything that *evaluates* to
a character string containing a file name (or it can be a URL or
it can be a 'text connection').

Following the advice in read.csv, you might want to
read the 'R Data Import/Export' manual.


On Sat, 23 Sept 2023 at 20:23, Parkhurst, David <parkhurs using indiana.edu>
wrote:

> I know I should save it as a .csv file, which I have done.
> I’m told I should use the read_excel() function from the readxl package.
> My question is, how do I express the location of the file.  The file is
> named KurtzData.csv.
> Its location in my Mac files is DFPfiles/ae/FriendsMonroe/KurtzData.csv
> How exactly---What “, etc.---do I type with its name in the read_excel()
> function?
> It’s been a long time since I’ve used R.
> Thanks for any help.
>
>
>
>
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list