|
I am the proud owner of a new laptop since my old one died the other day.
Currently I have a dual-boot Windows 7 Home and Ubuntu 12.04 . I'll leave the Windows problems for another post. I know practically nothing about Linux so I am probably doing something stupid but ... at the moment I cannot seem read or write files in Ubuntu. I am not having any problem saving other documents to the hard drive and R , from my few simple tests, seems to be working okay otherwise. At the moment I am trying : mydata <- read.csv("DATA/media/DATA/rdata/tt1.csv", header = TRUE) or mydata <- read.csv("DATA/rdata/tt1.csv", header = TRUE) where tt1.csv is a text file on what, from my reading of the path listed in gedit is DATA/media/DATA/rdata The csv data is simply: aa, bb 2, 3 4, 5 What happens: ------------------------------------------------------------------------------- 1> mydata <- read.csv("DATA/rdata/tt1.csv", header = TRUE) Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") : cannot open file 'DATA/rdata/tt1.csv': No such file or directory Am I totally screwing up the path? Or doing something else equally stupid? BTW I realise that 2.15 is out but Ubuntu as of yesterday did not have it in the repositories and I have yet to figure out how to install it from a CRAN site. 1> sessionInfo() R version 2.14.1 (2011-12-22) Platform: i686-pc-linux-gnu (32-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_CA.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base John Kane Kingston ON Canada ____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! ______________________________________________ [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 and provide commented, minimal, self-contained, reproducible code. |
|
Hi John,
You're probably messing up the path, just as you suspect. If you use a relative path, like you are doing, then R looks for that location starting at R's current working directory, visible with getwd(). For linux, that's the location at which you started R if you started it from a terminal. The safest solution is to use an absolute path, which will likely be something resembling "/home/john/DATA/... etc" - note that it will always start with a / and go from there. If you know how to start a terminal window and cd to where your file is, pwd at the command prompt will give you the absolute path to that location, which is what you should be using until you get more comfortable with the file system. The error message means that R can't find the directory you're telling it to use. Sarah On Thu, May 3, 2012 at 12:21 PM, John Kane <[hidden email]> wrote: > I am the proud owner of a new laptop since my old one died the other day. > Currently I have a dual-boot Windows 7 Home and Ubuntu 12.04 . I'll leave the Windows problems for another post. > > I know practically nothing about Linux so I am probably doing something stupid but ... at the moment I cannot seem read or write files in Ubuntu. I am not having any problem saving other documents to the hard drive and R , from my few simple tests, seems to be working okay otherwise. > > At the moment I am trying : > > mydata <- read.csv("DATA/media/DATA/rdata/tt1.csv", header = TRUE) > or > mydata <- read.csv("DATA/rdata/tt1.csv", header = TRUE) > > > where tt1.csv is a text file on what, from my reading of the path listed in gedit is > DATA/media/DATA/rdata > > The csv data is simply: > aa, bb > 2, 3 > 4, 5 > > What happens: > ------------------------------------------------------------------------------- > 1> mydata <- read.csv("DATA/rdata/tt1.csv", header = TRUE) > Error in file(file, "rt") : cannot open the connection > In addition: Warning message: > In file(file, "rt") : > cannot open file 'DATA/rdata/tt1.csv': No such file or directory > > Am I totally screwing up the path? Or doing something else equally stupid? > > BTW I realise that 2.15 is out but Ubuntu as of yesterday did not have it in the repositories and I have yet to figure out how to install it from a CRAN site. > > 1> sessionInfo() > R version 2.14.1 (2011-12-22) > Platform: i686-pc-linux-gnu (32-bit) > > locale: > [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C > [3] LC_TIME=en_CA.UTF-8 LC_COLLATE=en_US.UTF-8 > [5] LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_US.UTF-8 > [7] LC_PAPER=C LC_NAME=C > [9] LC_ADDRESS=C LC_TELEPHONE=C > [11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C > > attached base packages: > [1] stats graphics grDevices utils datasets methods base -- Sarah Goslee http://www.functionaldiversity.org ______________________________________________ [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 and provide commented, minimal, self-contained, reproducible code. |
|
In reply to this post by John Kane
All of your tests are with relative paths. Use getwd() identify your starting directory, and if it isn't you can use setwd() to start in the right place.
--------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<[hidden email]> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. John Kane <[hidden email]> wrote: >I am the proud owner of a new laptop since my old one died the other >day. >Currently I have a dual-boot Windows 7 Home and Ubuntu 12.04 . I'll >leave the Windows problems for another post. > >I know practically nothing about Linux so I am probably doing something >stupid but ... at the moment I cannot seem read or write files in >Ubuntu. I am not having any problem saving other documents to the >hard drive and R , from my few simple tests, seems to be working okay >otherwise. > >At the moment I am trying : > >mydata <- read.csv("DATA/media/DATA/rdata/tt1.csv", header = TRUE) > or >mydata <- read.csv("DATA/rdata/tt1.csv", header = TRUE) > > >where tt1.csv is a text file on what, from my reading of the path >listed in gedit is >DATA/media/DATA/rdata > >The csv data is simply: >aa, bb >2, 3 >4, 5 > >What happens: >------------------------------------------------------------------------------- >1> mydata <- read.csv("DATA/rdata/tt1.csv", header = TRUE) >Error in file(file, "rt") : cannot open the connection >In addition: Warning message: >In file(file, "rt") : > cannot open file 'DATA/rdata/tt1.csv': No such file or directory > >Am I totally screwing up the path? Or doing something else equally >stupid? > >BTW I realise that 2.15 is out but Ubuntu as of yesterday did not have >it in the repositories and I have yet to figure out how to install it >from a CRAN site. > >1> sessionInfo() >R version 2.14.1 (2011-12-22) >Platform: i686-pc-linux-gnu (32-bit) > >locale: > [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C > [3] LC_TIME=en_CA.UTF-8 LC_COLLATE=en_US.UTF-8 > [5] LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_US.UTF-8 > [7] LC_PAPER=C LC_NAME=C > [9] LC_ADDRESS=C LC_TELEPHONE=C >[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C > >attached base packages: >[1] stats graphics grDevices utils datasets methods base > > >John Kane >Kingston ON Canada > >____________________________________________________________ >FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! > >______________________________________________ >[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 >and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [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 and provide commented, minimal, self-contained, reproducible code. |
|
In reply to this post by Sarah Goslee
Thanks Sarah,
I suspected something like that but am still gropping around in Linux. I vaguely remember how to cd to someplace. Shades of DOS 3.2! Of was that Unixor both! Also I think I was trying to be a bit too smart-alecky in where I was placing my data folder so I moved it to my home folder to simplify figuring out the path. Still thinking in Windows terms. After a bit of trial and error: jjohn@john-K53U:~$ cd /home/john/rdata john@john-K53U:~/rdata$ dir tti.csv john@john-K53U:~/rdata$ pwd /home/john/rdata so mydata <- read.csv("/home/john/rdata/tti.csv", header = TRUE) works just fine. I like the idea of staying with absolute paths. I am most appreciative. John Kane Kingston ON Canada > -----Original Message----- > From: [hidden email] > Sent: Thu, 3 May 2012 12:29:14 -0400 > To: [hidden email] > Subject: Re: [R] Cannot read or write to file in Linux Ubuntu > > Hi John, > > You're probably messing up the path, just as you suspect. > > If you use a relative path, like you are doing, then R looks for that > location starting at R's current working directory, visible with > getwd(). For linux, that's the location at which you started R if you > started it from a terminal. > > The safest solution is to use an absolute path, which will likely be > something resembling "/home/john/DATA/... etc" - note that it will > always start with a / and go from there. > > If you know how to start a terminal window and cd to where your file > is, pwd at the command prompt will give you the absolute path to that > location, which is what you should be using until you get more > comfortable with the file system. > > The error message means that R can't find the directory you're telling > it to use. > > Sarah > > On Thu, May 3, 2012 at 12:21 PM, John Kane <[hidden email]> wrote: >> I am the proud owner of a new laptop since my old one died the other >> day. >> Currently I have a dual-boot Windows 7 Home and Ubuntu 12.04 . I'll >> leave the Windows problems for another post. >> >> I know practically nothing about Linux so I am probably doing something >> stupid but ... at the moment I cannot seem read or write files in >> Ubuntu. I am not having any problem saving other documents to the hard >> drive and R , from my few simple tests, seems to be working okay >> otherwise. >> >> At the moment I am trying : >> >> mydata <- read.csv("DATA/media/DATA/rdata/tt1.csv", header = TRUE) >> or >> mydata <- read.csv("DATA/rdata/tt1.csv", header = TRUE) >> >> >> where tt1.csv is a text file on what, from my reading of the path listed >> in gedit is >> DATA/media/DATA/rdata >> >> The csv data is simply: >> aa, bb >> 2, 3 >> 4, 5 >> >> What happens: >> ------------------------------------------------------------------------------- >> 1> mydata <- read.csv("DATA/rdata/tt1.csv", header = TRUE) >> Error in file(file, "rt") : cannot open the connection >> In addition: Warning message: >> In file(file, "rt") : >> cannot open file 'DATA/rdata/tt1.csv': No such file or directory >> >> Am I totally screwing up the path? Or doing something else equally >> stupid? >> >> BTW I realise that 2.15 is out but Ubuntu as of yesterday did not have >> it in the repositories and I have yet to figure out how to install it >> from a CRAN site. >> >> 1> sessionInfo() >> R version 2.14.1 (2011-12-22) >> Platform: i686-pc-linux-gnu (32-bit) >> >> locale: >> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C >> [3] LC_TIME=en_CA.UTF-8 LC_COLLATE=en_US.UTF-8 >> [5] LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_US.UTF-8 >> [7] LC_PAPER=C LC_NAME=C >> [9] LC_ADDRESS=C LC_TELEPHONE=C >> [11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C >> >> attached base packages: >> [1] stats graphics grDevices utils datasets methods base > > -- > Sarah Goslee > http://www.functionaldiversity.org ____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! ______________________________________________ [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 and provide commented, minimal, self-contained, reproducible code. |
|
In reply to this post by Jeff Newmiller
Thanks.
I had not realsed there were relative paths until Sarah mentioned them. It's working now: see my post to Sarah. John Kane Kingston ON Canada > -----Original Message----- > From: [hidden email] > Sent: Thu, 03 May 2012 09:30:10 -0700 > To: [hidden email], [hidden email] > Subject: Re: [R] Cannot read or write to file in Linux Ubuntu > > All of your tests are with relative paths. Use getwd() identify your > starting directory, and if it isn't you can use setwd() to start in the > right place. > --------------------------------------------------------------------------- > Jeff Newmiller The ..... ..... Go > Live... > DCN:<[hidden email]> Basics: ##.#. ##.#. Live > Go... > Live: OO#.. Dead: OO#.. Playing > Research Engineer (Solar/Batteries O.O#. #.O#. with > /Software/Embedded Controllers) .OO#. .OO#. > rocks...1k > --------------------------------------------------------------------------- > Sent from my phone. Please excuse my brevity. > > John Kane <[hidden email]> wrote: > > >I am the proud owner of a new laptop since my old one died the other > >day. > >Currently I have a dual-boot Windows 7 Home and Ubuntu 12.04 . I'll > >leave the Windows problems for another post. >> > >I know practically nothing about Linux so I am probably doing something > >stupid but ... at the moment I cannot seem read or write files in > >Ubuntu. I am not having any problem saving other documents to the > >hard drive and R , from my few simple tests, seems to be working okay > >otherwise. >> > >At the moment I am trying : >> > >mydata <- read.csv("DATA/media/DATA/rdata/tt1.csv", header = TRUE) >> or > >mydata <- read.csv("DATA/rdata/tt1.csv", header = TRUE) >> >> > >where tt1.csv is a text file on what, from my reading of the path > >listed in gedit is > >DATA/media/DATA/rdata >> > >The csv data is simply: > >aa, bb > >2, 3 > >4, 5 >> > >What happens: > >------------------------------------------------------------------------------- > >1> mydata <- read.csv("DATA/rdata/tt1.csv", header = TRUE) > >Error in file(file, "rt") : cannot open the connection > >In addition: Warning message: > >In file(file, "rt") : >> cannot open file 'DATA/rdata/tt1.csv': No such file or directory >> > >Am I totally screwing up the path? Or doing something else equally > >stupid? >> > >BTW I realise that 2.15 is out but Ubuntu as of yesterday did not have > >it in the repositories and I have yet to figure out how to install it > >from a CRAN site. >> > >1> sessionInfo() > >R version 2.14.1 (2011-12-22) > >Platform: i686-pc-linux-gnu (32-bit) >> > >locale: >> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C >> [3] LC_TIME=en_CA.UTF-8 LC_COLLATE=en_US.UTF-8 >> [5] LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_US.UTF-8 >> [7] LC_PAPER=C LC_NAME=C >> [9] LC_ADDRESS=C LC_TELEPHONE=C > >[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C >> > >attached base packages: > >[1] stats graphics grDevices utils datasets methods base >> >> > >John Kane > >Kingston ON Canada >> > >____________________________________________________________ > >FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! >> > >______________________________________________ > >[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 > >and provide commented, minimal, self-contained, reproducible code. ____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop! ______________________________________________ [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 and provide commented, minimal, self-contained, reproducible code. |
|
In reply to this post by John Kane
"I like the idea of staying with absolute paths."
Before you write too much R code that builds in absolute paths, please consider how difficult it will be to adjust all of those paths if you need to run on a different computer or you need to reorganize your overall directory structure. If you keep related R files in the same project directory, you can collapse all of those paths down to short relative paths, and do one setwd at the beginning, or learn to manually set your base working directory as a matter of habit before each working session. (This habit is useful in more areas than just R programming.) --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<[hidden email]> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. John Kane <[hidden email]> wrote: >Thanks Sarah, > >I suspected something like that but am still gropping around in Linux. >I vaguely remember how to cd to someplace. Shades of DOS 3.2! Of was >that Unixor both! > >Also I think I was trying to be a bit too smart-alecky in where I was >placing my data folder so I moved it to my home folder to simplify >figuring out the path. Still thinking in Windows terms. > >After a bit of trial and error: > >jjohn@john-K53U:~$ cd /home/john/rdata >john@john-K53U:~/rdata$ dir >tti.csv >john@john-K53U:~/rdata$ pwd >/home/john/rdata > >so >mydata <- read.csv("/home/john/rdata/tti.csv", header = TRUE) > works just fine. I like the idea of staying with absolute paths. > >I am most appreciative. > >John Kane >Kingston ON Canada > > >> -----Original Message----- >> From: [hidden email] >> Sent: Thu, 3 May 2012 12:29:14 -0400 >> To: [hidden email] >> Subject: Re: [R] Cannot read or write to file in Linux Ubuntu >> >> Hi John, >> >> You're probably messing up the path, just as you suspect. >> >> If you use a relative path, like you are doing, then R looks for that >> location starting at R's current working directory, visible with >> getwd(). For linux, that's the location at which you started R if you >> started it from a terminal. >> >> The safest solution is to use an absolute path, which will likely be >> something resembling "/home/john/DATA/... etc" - note that it will >> always start with a / and go from there. >> >> If you know how to start a terminal window and cd to where your file >> is, pwd at the command prompt will give you the absolute path to that >> location, which is what you should be using until you get more >> comfortable with the file system. >> >> The error message means that R can't find the directory you're >telling >> it to use. >> >> Sarah >> >> On Thu, May 3, 2012 at 12:21 PM, John Kane <[hidden email]> >wrote: >>> I am the proud owner of a new laptop since my old one died the other >>> day. >>> Currently I have a dual-boot Windows 7 Home and Ubuntu 12.04 . I'll >>> leave the Windows problems for another post. >>> >>> I know practically nothing about Linux so I am probably doing >something >>> stupid but ... at the moment I cannot seem read or write files in >>> Ubuntu. I am not having any problem saving other documents to the >hard >>> drive and R , from my few simple tests, seems to be working okay >>> otherwise. >>> >>> At the moment I am trying : >>> >>> mydata <- read.csv("DATA/media/DATA/rdata/tt1.csv", header = TRUE) >>> or >>> mydata <- read.csv("DATA/rdata/tt1.csv", header = TRUE) >>> >>> >>> where tt1.csv is a text file on what, from my reading of the path >listed >>> in gedit is >>> DATA/media/DATA/rdata >>> >>> The csv data is simply: >>> aa, bb >>> 2, 3 >>> 4, 5 >>> >>> What happens: >>> >------------------------------------------------------------------------------- >>> 1> mydata <- read.csv("DATA/rdata/tt1.csv", header = TRUE) >>> Error in file(file, "rt") : cannot open the connection >>> In addition: Warning message: >>> In file(file, "rt") : >>> cannot open file 'DATA/rdata/tt1.csv': No such file or directory >>> >>> Am I totally screwing up the path? Or doing something else equally >>> stupid? >>> >>> BTW I realise that 2.15 is out but Ubuntu as of yesterday did not >have >>> it in the repositories and I have yet to figure out how to install >it >>> from a CRAN site. >>> >>> 1> sessionInfo() >>> R version 2.14.1 (2011-12-22) >>> Platform: i686-pc-linux-gnu (32-bit) >>> >>> locale: >>> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C >>> [3] LC_TIME=en_CA.UTF-8 LC_COLLATE=en_US.UTF-8 >>> [5] LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_US.UTF-8 >>> [7] LC_PAPER=C LC_NAME=C >>> [9] LC_ADDRESS=C LC_TELEPHONE=C >>> [11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C >>> >>> attached base packages: >>> [1] stats graphics grDevices utils datasets methods base >> >> -- >> Sarah Goslee >> http://www.functionaldiversity.org > >____________________________________________________________ >FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! > >______________________________________________ >[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 >and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [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 and provide commented, minimal, self-contained, reproducible code. |
|
On Thu, May 3, 2012 at 1:53 PM, Jeff Newmiller <[hidden email]> wrote:
> "I like the idea of staying with absolute paths." > > Before you write too much R code that builds in absolute paths, please consider how difficult it will be to adjust all of those paths if you need to run on a different computer or you need to reorganize your overall directory structure. If you keep related R files in the same project directory, you can collapse all of those paths down to short relative paths, and do one setwd at the beginning, or learn to manually set your base working directory as a matter of habit before each working session. (This habit is useful in more areas than just R programming.) I agree with this, which is why I suggested you use absolute paths *until you get more comfortable with the file system.* It's a good way to diagnose your problem and figure out how to deal with paths on Linux, but not a good long-term strategy unless you expect that you will never ever move anything or change to a new computer. An intermediate solution that I use a lot is to put something like this at the beginning of R script file: basepath = "/home/sarahg/whatever" and then load files using something like read.table(paste(basepath, "plantdata.csv", sep="/")) This eases portability between computers: I exchange a lot of analyses with postdocs, students and techs, and somehow they've not all become convinced that my way of organizing directories is the best one. Using an object with the absolute path for the data means that we can pass things back and forth with only changing one value within the script rather than all input/output commands. Sarah -- Sarah Goslee http://www.functionaldiversity.org ______________________________________________ [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 and provide commented, minimal, self-contained, reproducible code. |
|
Thanks Jeff and Sarah.
I was thinking mainly of using the base path and paste routine which is something I do in Windows It will take me a while to figrue out relative paths. John Kane Kingston ON Canada > -----Original Message----- > From: [hidden email] > Sent: Thu, 3 May 2012 14:07:12 -0400 > To: [hidden email] > Subject: Re: [R] Cannot read or write to file in Linux Ubuntu > > On Thu, May 3, 2012 at 1:53 PM, Jeff Newmiller <[hidden email]> > wrote: >> "I like the idea of staying with absolute paths." >> >> Before you write too much R code that builds in absolute paths, please >> consider how difficult it will be to adjust all of those paths if you >> need to run on a different computer or you need to reorganize your >> overall directory structure. If you keep related R files in the same >> project directory, you can collapse all of those paths down to short >> relative paths, and do one setwd at the beginning, or learn to manually >> set your base working directory as a matter of habit before each working >> session. (This habit is useful in more areas than just R programming.) > > I agree with this, which is why I suggested you use absolute paths > *until you get more comfortable with the file system.* It's a good way > to diagnose your problem and figure out how to deal with paths on > Linux, but not a good long-term strategy unless you expect that you > will never ever move anything or change to a new computer. > > An intermediate solution that I use a lot is to put something like > this at the beginning of R script file: > basepath = "/home/sarahg/whatever" > and then load files using something like > read.table(paste(basepath, "plantdata.csv", sep="/")) > > This eases portability between computers: I exchange a lot of analyses > with postdocs, students and techs, and somehow they've not all become > convinced that my way of organizing directories is the best one. Using > an object with the absolute path for the data means that we can pass > things back and forth with only changing one value within the script > rather than all input/output commands. > > Sarah > > -- > Sarah Goslee > http://www.functionaldiversity.org > ____________________________________________________________ TRY FREE IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if5 Capture screenshots, upload images, edit and send them to your friends through IMs, post on Twitter®, Facebook®, MySpace™, LinkedIn® – FAST! ______________________________________________ [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 and provide commented, minimal, self-contained, reproducible code. |
|
On Thu, 3 May 2012 10:50:46 -0800
John Kane <[hidden email]> wrote: > Thanks Jeff and Sarah. > > I was thinking mainly of using the base path and paste routine which > is something I do in Windows > > It will take me a while to figrue out relative paths. > Relative paths are not a mystery nor are they solely an aspect of linux. They are in fact the norm in DOS and Windows as well as in Linux or any other file system that use a "tree" structure. Since Windows constrains you to a graphic interface, when using the file manager, you see the default use of relative paths without recognizing the behaviour. When opening or saving a file in Windows, the system will often offer you the choice of 'save, or 'save as' and if you mistakenly use 'save' from the wrong working directory, you may well have a files written other than where you thought it was. This problem is so common that Windows users tend to take it in stride and have developed habits that limit the aggravation. You do not have those habits for Linux yet. Until you are more comfortable in Linux you might want to run RStudio while using R. The learning curve of a new OS as well as different details in simply using the computer interface is quite challenging. JWDougherty ______________________________________________ [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 and provide commented, minimal, self-contained, reproducible code. |
|
"Relative paths are not a mystery nor are they solely an aspect of linux.
> They are in fact the norm in DOS and Windows as well as in Linux or > any other file system that use a "tree" structure." Oh, is that all! I just never thought of that behaviour as 'relative paths' just as something that one had to take into account in DOS. I may take a look at R Studio but so far I have been comfortable with a text editor and either RGUI or a terminal. thanks John Kane Kingston ON Canada > -----Original Message----- > From: [hidden email] > Sent: Fri, 4 May 2012 18:35:31 -0700 > To: [hidden email] > Subject: Re: [R] Cannot read or write to file in Linux Ubuntu > > On Thu, 3 May 2012 10:50:46 -0800 > John Kane <[hidden email]> wrote: > >> Thanks Jeff and Sarah. >> >> I was thinking mainly of using the base path and paste routine which >> is something I do in Windows >> >> It will take me a while to figrue out relative paths. >> > Relative paths are not a mystery nor are they solely an aspect of linux. > They are in fact the norm in DOS and Windows as well as in Linux or > any other file system that use a "tree" structure. Since Windows > constrains you to a graphic interface, when using the file manager, you > see the default use of relative paths without recognizing the > behaviour. > > When opening or saving a file in Windows, the system will often offer > you the choice of 'save, or 'save as' and if you mistakenly use 'save' > from the wrong working directory, you may well have a files written > other than where you thought it was. This problem is so common that > Windows users tend to take it in stride and have developed habits that > limit the aggravation. You do not have those habits for Linux yet. > > Until you are more comfortable in Linux you might want to run RStudio > while using R. The learning curve of a new OS as well as > different details in simply using the computer interface is quite > challenging. > > JWDougherty > > ______________________________________________ > [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 > and provide commented, minimal, self-contained, reproducible code. ____________________________________________________________ FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! ______________________________________________ [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 and provide commented, minimal, self-contained, reproducible code. |
|
In reply to this post by John Kane
Hello,
I have a similar issue , but in my case I am using Windows 7 i try the following command to write a dataframe to xls using the xlsReadWrite package or the write.csv function write.xls(DATA,'Reg_IDcleaned.xls') or I will write.csv replacin the suffix with .csv I get absolutely no error message and the setwd appears at top of my code with absolute path However when I look in the relevant folder ,the xls or cdv outfile is nowhere to be found. Is there a gremlin in the computer or what? Before, this write.xls was working fine and now it stopped, i used the write.csv to test if it was an error in the package. So since write.csv also fails to produce the oufile in .csv in the relevant folder, I am at my witts end |
|
On Thu, Sep 13, 2012 at 4:05 PM, pmulonge
<[hidden email]> wrote: > Hello, > I have a similar issue , but in my case I am using Windows 7 > i try the following command to write a dataframe to xls using the > xlsReadWrite package or the write.csv function > write.xls(DATA,'Reg_IDcleaned.xls') > or I will write.csv replacin the suffix with .csv > I get absolutely no error message and the setwd appears at top of my code > with absolute path > However when I look in the relevant folder ,the xls or cdv outfile is > nowhere to be found. > Is there a gremlin in the computer or what? It seems unlikely, but I suppose it can't be ruled out.... > Before, this write.xls was working fine and now it stopped, i used the > write.csv to test if it was an error in the package. > So since write.csv also fails to produce the oufile in .csv in the relevant > folder, I am at my witts end > Firstly, please do quote context: most of us don't read nabble and I have no idea what "similar problem" you're having. (Well, actually, I clicked the link and I do, but I'm not letting on) Secondly, can you whip up a reproducible example? http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example I see no reason why setwd("~") # Replace with appropriate Windows-ism write.csv(data.frame(1:5, letters[1:5])) wouldn't work if you have the right permissions, but perhaps you are doing something funny. Cheers, Michael ______________________________________________ [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 and provide commented, minimal, self-contained, reproducible code. |
|
> -----Original Message----- > From: [hidden email] [mailto:[hidden email]] On Behalf > Of R. Michael Weylandt > Sent: Thursday, September 13, 2012 2:52 PM > To: pmulonge > Cc: [hidden email] > Subject: Re: [R] Cannot write a dataframe to xls or csv Windows 7 > > On Thu, Sep 13, 2012 at 4:05 PM, pmulonge > <[hidden email]> wrote: > > Hello, > > I have a similar issue , but in my case I am using Windows 7 > > i try the following command to write a dataframe to xls using the > > xlsReadWrite package or the write.csv function > > write.xls(DATA,'Reg_IDcleaned.xls') > > or I will write.csv replacin the suffix with .csv > > I get absolutely no error message and the setwd appears at top of my code > > with absolute path Immediately after the write.xls(..., file="something") run normalizePath("something", mustWork=TRUE) and it should give a full path to the file called "something". Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > > However when I look in the relevant folder ,the xls or cdv outfile is > > nowhere to be found. > > Is there a gremlin in the computer or what? > > It seems unlikely, but I suppose it can't be ruled out.... > > > Before, this write.xls was working fine and now it stopped, i used the > > write.csv to test if it was an error in the package. > > So since write.csv also fails to produce the oufile in .csv in the relevant > > folder, I am at my witts end > > > > Firstly, please do quote context: most of us don't read nabble and I > have no idea what "similar problem" you're having. (Well, actually, I > clicked the link and I do, but I'm not letting on) Secondly, can you > whip up a reproducible example? > > http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible- > example > > I see no reason why > > setwd("~") # Replace with appropriate Windows-ism > write.csv(data.frame(1:5, letters[1:5])) > > wouldn't work if you have the right permissions, but perhaps you are > doing something funny. > > Cheers, > Michael > > ______________________________________________ > [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 > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [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 and provide commented, minimal, self-contained, reproducible code. |
|
Thank you so much,
Yes I need to look up how to make a reproducible example, William I will try your advice, I believe this will be my salvation here, once I get my computer. Pancho On Sep 13, 2012, at 23:59, "William Dunlap" <[hidden email]> wrote: > >> -----Original Message----- >> From: [hidden email] [mailto:[hidden email]] On Behalf >> Of R. Michael Weylandt >> Sent: Thursday, September 13, 2012 2:52 PM >> To: pmulonge >> Cc: [hidden email] >> Subject: Re: [R] Cannot write a dataframe to xls or csv Windows 7 >> >> On Thu, Sep 13, 2012 at 4:05 PM, pmulonge >> <[hidden email]> wrote: >>> Hello, >>> I have a similar issue , but in my case I am using Windows 7 >>> i try the following command to write a dataframe to xls using the >>> xlsReadWrite package or the write.csv function >>> write.xls(DATA,'Reg_IDcleaned.xls') >>> or I will write.csv replacin the suffix with .csv >>> I get absolutely no error message and the setwd appears at top of my code >>> with absolute path > > Immediately after the write.xls(..., file="something") run > normalizePath("something", mustWork=TRUE) > and it should give a full path to the file called "something". > > Bill Dunlap > Spotfire, TIBCO Software > wdunlap tibco.com > >>> However when I look in the relevant folder ,the xls or cdv outfile is >>> nowhere to be found. >>> Is there a gremlin in the computer or what? >> >> It seems unlikely, but I suppose it can't be ruled out.... >> >>> Before, this write.xls was working fine and now it stopped, i used the >>> write.csv to test if it was an error in the package. >>> So since write.csv also fails to produce the oufile in .csv in the relevant >>> folder, I am at my witts end >>> >> >> Firstly, please do quote context: most of us don't read nabble and I >> have no idea what "similar problem" you're having. (Well, actually, I >> clicked the link and I do, but I'm not letting on) Secondly, can you >> whip up a reproducible example? >> >> http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible- >> example >> >> I see no reason why >> >> setwd("~") # Replace with appropriate Windows-ism >> write.csv(data.frame(1:5, letters[1:5])) >> >> wouldn't work if you have the right permissions, but perhaps you are >> doing something funny. >> >> Cheers, >> Michael >> >> ______________________________________________ >> [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 >> and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ [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 and provide commented, minimal, self-contained, reproducible code. |
| Powered by Nabble | Edit this page |
