How do I tell it which directory to use?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

How do I tell it which directory to use?

Thomas L Jones
>From Tom:

In R 2.2.0 under Windows, I want to be able to give it a filename such
as "myFile.txt" without the quotes. But actually I mean:

C:\Documents and Settings\Tom\My Documents\qpaper7\R Project Started
19 Dec 05\myFile.txt

If I were to repeat this each time, my computer would get all bored
and cranky and start to drop bits (only a joke, of course). I think I
want to set the Home directory or the working directory or some
directory or other to the above directory. I may or may not want to
set some environmental variables.

R 2.2.0; working directly from the console and copying and pasting
code which I want to test into the console. Windows XP Home Edition.
Administrator privileges are enabled. A curve ball: There are two
accounts, "Tom" and "Jones;" the data are stored under "Tom," whereas
the computation is being done under the "Jones" account. I won't bore
you with the details of why I am doing this.

I was able to call Sys.getenv ("R_USER") and get the home directory.

I am a newbie to R and not familiar with the terminology.

Tom
Thomas L. Jones, Ph.D., Computer Science

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: How do I tell it which directory to use?

Simon Blomberg-2
I think you want getwd() and setwd().

HTH,

Simon.

Thomas L Jones wrote:

> >From Tom:
>
> In R 2.2.0 under Windows, I want to be able to give it a filename such
> as "myFile.txt" without the quotes. But actually I mean:
>
> C:\Documents and Settings\Tom\My Documents\qpaper7\R Project Started
> 19 Dec 05\myFile.txt
>
> If I were to repeat this each time, my computer would get all bored
> and cranky and start to drop bits (only a joke, of course). I think I
> want to set the Home directory or the working directory or some
> directory or other to the above directory. I may or may not want to
> set some environmental variables.
>
> R 2.2.0; working directly from the console and copying and pasting
> code which I want to test into the console. Windows XP Home Edition.
> Administrator privileges are enabled. A curve ball: There are two
> accounts, "Tom" and "Jones;" the data are stored under "Tom," whereas
> the computation is being done under the "Jones" account. I won't bore
> you with the details of why I am doing this.
>
> I was able to call Sys.getenv ("R_USER") and get the home directory.
>
> I am a newbie to R and not familiar with the terminology.
>
> Tom
> Thomas L. Jones, Ph.D., Computer Science
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>  


--
Simon Blomberg, B.Sc.(Hons.), Ph.D, M.App.Stat.
Centre for Resource and Environmental Studies
The Australian National University
Canberra ACT 0200
Australia
T: +61 2 6125 7800 email: Simon.Blomberg_at_anu.edu.au
F: +61 2 6125 0757
CRICOS Provider # 00120C

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: How do I tell it which directory to use?

Augusto.Sanabria
In reply to this post by Thomas L Jones

Tom,

You can define your working directory by using:

setwd("C:\Documents and Settings\Tom\My Documents\qpaper7\R Project Started
19 Dec 05")

check that your file is there:
list.files()

and then use:

source("myFile.txt")

the machine should load "myFile"

You can go to another directory:
setwd("anotherdir")

and repeat the procedure.

Or even better if you define a number of directories in an external file:

dir1 <- c(C:\Documents and Settings\Tom\My Documents\qpaper7\")
dir2 <- c(C:\Documents and Settings\Tom\My Documents\")

and after loading the file at the beginning of the sesion you can use:

setwd("dir1")  etc.

Is it of any help to you?

Cheers,

Augusto


--------------------------------------------
Augusto Sanabria. MSc, PhD.
Mathematical Modeller
Risk Research Group
Geospatial & Earth Monitoring Division
Geoscience Australia (www.ga.gov.au)
Cnr. Jerrabomberra Av. & Hindmarsh Dr.
Symonston ACT 2609
Ph. (02) 6249-9155
 

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Thomas L Jones
Sent: Wednesday, 22 February 2006 4:31 PM
To: R-project help
Subject: [R] How do I tell it which directory to use?


>From Tom:

In R 2.2.0 under Windows, I want to be able to give it a filename such
as "myFile.txt" without the quotes. But actually I mean:

C:\Documents and Settings\Tom\My Documents\qpaper7\R Project Started
19 Dec 05\myFile.txt

If I were to repeat this each time, my computer would get all bored
and cranky and start to drop bits (only a joke, of course). I think I
want to set the Home directory or the working directory or some
directory or other to the above directory. I may or may not want to
set some environmental variables.

R 2.2.0; working directly from the console and copying and pasting
code which I want to test into the console. Windows XP Home Edition.
Administrator privileges are enabled. A curve ball: There are two
accounts, "Tom" and "Jones;" the data are stored under "Tom," whereas
the computation is being done under the "Jones" account. I won't bore
you with the details of why I am doing this.

I was able to call Sys.getenv ("R_USER") and get the home directory.

I am a newbie to R and not familiar with the terminology.

Tom
Thomas L. Jones, Ph.D., Computer Science

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: How do I tell it which directory to use?

Uwe Ligges
[hidden email] wrote:
> Tom,
>
> You can define your working directory by using:
>
> setwd("C:\Documents and Settings\Tom\My Documents\qpaper7\R Project Started
> 19 Dec 05")

Thanks for your contribution to R-help, but:

No, see the R for Windows FAQs which tell you to use "\\" or "/" rather
than "\"!


>
> check that your file is there:
> list.files()
>
> and then use:
>
> source("myFile.txt")
>
> the machine should load "myFile"
>
> You can go to another directory:
> setwd("anotherdir")
>
> and repeat the procedure.
>
> Or even better if you define a number of directories in an external file:
>
> dir1 <- c(C:\Documents and Settings\Tom\My Documents\qpaper7\")
> dir2 <- c(C:\Documents and Settings\Tom\My Documents\")

See above + don't forget the quotes!


> and after loading the file at the beginning of the sesion you can use:
>
> setwd("dir1")  etc.

In this case without quotes!

  setwd(dir1)

Please don't confuse other R-help readers and try to be more precise in
your answers.

Uwe Ligges


> Is it of any help to you?
> Cheers,
>
> Augusto
>
>
> --------------------------------------------
> Augusto Sanabria. MSc, PhD.
> Mathematical Modeller
> Risk Research Group
> Geospatial & Earth Monitoring Division
> Geoscience Australia (www.ga.gov.au)
> Cnr. Jerrabomberra Av. & Hindmarsh Dr.
> Symonston ACT 2609
> Ph. (02) 6249-9155
>  
>
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Thomas L Jones
> Sent: Wednesday, 22 February 2006 4:31 PM
> To: R-project help
> Subject: [R] How do I tell it which directory to use?
>
>
>>From Tom:
>
> In R 2.2.0 under Windows, I want to be able to give it a filename such
> as "myFile.txt" without the quotes. But actually I mean:
>
> C:\Documents and Settings\Tom\My Documents\qpaper7\R Project Started
> 19 Dec 05\myFile.txt
>
> If I were to repeat this each time, my computer would get all bored
> and cranky and start to drop bits (only a joke, of course). I think I
> want to set the Home directory or the working directory or some
> directory or other to the above directory. I may or may not want to
> set some environmental variables.
>
> R 2.2.0; working directly from the console and copying and pasting
> code which I want to test into the console. Windows XP Home Edition.
> Administrator privileges are enabled. A curve ball: There are two
> accounts, "Tom" and "Jones;" the data are stored under "Tom," whereas
> the computation is being done under the "Jones" account. I won't bore
> you with the details of why I am doing this.
>
> I was able to call Sys.getenv ("R_USER") and get the home directory.
>
> I am a newbie to R and not familiar with the terminology.
>
> Tom
> Thomas L. Jones, Ph.D., Computer Science
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: How do I tell it which directory to use?

Adaikalavan Ramasamy
In reply to this post by Augusto.Sanabria
I think the idea of defining dir1 and dir2 is a good one. If you want to
simplify life even further, you can put these into files that get
initialised when R starts. See help(Startup) for details.

Regards, Adai


On Wed, 2006-02-22 at 16:54 +1100, [hidden email] wrote:

> Tom,
>
> You can define your working directory by using:
>
> setwd("C:\Documents and Settings\Tom\My Documents\qpaper7\R Project Started
> 19 Dec 05")
>
> check that your file is there:
> list.files()
>
> and then use:
>
> source("myFile.txt")
>
> the machine should load "myFile"
>
> You can go to another directory:
> setwd("anotherdir")
>
> and repeat the procedure.
>
> Or even better if you define a number of directories in an external file:
>
> dir1 <- c(C:\Documents and Settings\Tom\My Documents\qpaper7\")
> dir2 <- c(C:\Documents and Settings\Tom\My Documents\")
>
> and after loading the file at the beginning of the sesion you can use:
>
> setwd("dir1")  etc.
>
> Is it of any help to you?
>
> Cheers,
>
> Augusto
>
>
> --------------------------------------------
> Augusto Sanabria. MSc, PhD.
> Mathematical Modeller
> Risk Research Group
> Geospatial & Earth Monitoring Division
> Geoscience Australia (www.ga.gov.au)
> Cnr. Jerrabomberra Av. & Hindmarsh Dr.
> Symonston ACT 2609
> Ph. (02) 6249-9155
>  
>
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Thomas L Jones
> Sent: Wednesday, 22 February 2006 4:31 PM
> To: R-project help
> Subject: [R] How do I tell it which directory to use?
>
>
> >From Tom:
>
> In R 2.2.0 under Windows, I want to be able to give it a filename such
> as "myFile.txt" without the quotes. But actually I mean:
>
> C:\Documents and Settings\Tom\My Documents\qpaper7\R Project Started
> 19 Dec 05\myFile.txt
>
> If I were to repeat this each time, my computer would get all bored
> and cranky and start to drop bits (only a joke, of course). I think I
> want to set the Home directory or the working directory or some
> directory or other to the above directory. I may or may not want to
> set some environmental variables.
>
> R 2.2.0; working directly from the console and copying and pasting
> code which I want to test into the console. Windows XP Home Edition.
> Administrator privileges are enabled. A curve ball: There are two
> accounts, "Tom" and "Jones;" the data are stored under "Tom," whereas
> the computation is being done under the "Jones" account. I won't bore
> you with the details of why I am doing this.
>
> I was able to call Sys.getenv ("R_USER") and get the home directory.
>
> I am a newbie to R and not familiar with the terminology.
>
> Tom
> Thomas L. Jones, Ph.D., Computer Science
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

read.table missing values

I.Szentirmai
Dear R users,

I'm trying to read data from a tab-delimited text file to
R, but I have problems with missing values. R gives this
kind of error messages: "line 1 did not have 9 elements".

Could someone tell me how I can deal with missing values
in this case?

Thanks a lot in advance,
Istvan

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: read.table missing values

Sean Davis
Does using read.delim instead of read.table fix your problem?

Sean


On 2/22/06 7:40 AM, "I.Szentirmai" <[hidden email]> wrote:

> Dear R users,
>
> I'm trying to read data from a tab-delimited text file to
> R, but I have problems with missing values. R gives this
> kind of error messages: "line 1 did not have 9 elements".
>
> Could someone tell me how I can deal with missing values
> in this case?
>
> Thanks a lot in advance,
> Istvan
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: read.table missing values

I.Szentirmai
might be, but I have already found another solution:
reat.table(file,sep="\t")

Thanks,
Istvan



On Wed, 22 Feb 2006 07:54:49 -0500
  Sean Davis <[hidden email]> wrote:

> Does using read.delim instead of read.table fix your
>problem?
>
> Sean
>
>
> On 2/22/06 7:40 AM, "I.Szentirmai" <[hidden email]>
>wrote:
>
>> Dear R users,
>>
>> I'm trying to read data from a tab-delimited text file
>>to
>> R, but I have problems with missing values. R gives this
>> kind of error messages: "line 1 did not have 9
>>elements".
>>
>> Could someone tell me how I can deal with missing values
>> in this case?
>>
>> Thanks a lot in advance,
>> Istvan
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>>http://www.R-project.org/posting-guide.html
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: read.table missing values

MMcIntosh
In reply to this post by I.Szentirmai
I have experienced a similar problem when saving Excel data in this
format.  When any of the variables, except the last, contained missing
values, there was not a problem.  However, the problem occurred when the
last variable contained missing values.  My guess is that the last
delimiter was left off?  The "fill" option worked in my case.  Use the
option with care and double check the dataset.

HTH
Matthew McIntosh



-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of I.Szentirmai
Sent: Wednesday, February 22, 2006 7:04 AM
To: r-help
Subject: Re: [R] read.table missing values

might be, but I have already found another solution:
reat.table(file,sep="\t")

Thanks,
Istvan



On Wed, 22 Feb 2006 07:54:49 -0500
  Sean Davis <[hidden email]> wrote:

> Does using read.delim instead of read.table fix your
>problem?
>
> Sean
>
>
> On 2/22/06 7:40 AM, "I.Szentirmai" <[hidden email]>
>wrote:
>
>> Dear R users,
>>
>> I'm trying to read data from a tab-delimited text file
>>to
>> R, but I have problems with missing values. R gives this
>> kind of error messages: "line 1 did not have 9
>>elements".
>>
>> Could someone tell me how I can deal with missing values
>> in this case?
>>
>> Thanks a lot in advance,
>> Istvan
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>>http://www.R-project.org/posting-guide.html
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html