Cannot open a result file in R with message permission denied.

I have received some code in R but when I run the code, I get the the following message at the end
Error in file(file, ifelse(append, "a", "w")) :
  cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
  cannot open file 'ptr.txt-3R.res': Permission denied
There is therefore a result file, but it cannot be opened!
I am supposed to get graphs as well as results, but I only get some results with no graphs which is suspect need to access the result file?
Why would it not be able to access the result file?
I am totally novice in R and rally lost as this code works perfectly in one of my colleagues desktop!
Daniele QuestiauxResearch associateAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Can you provide the line of code where you try to open the file ?

Daniele QuestiauxResearch associateAuthor Commented:
Hi Oli!

I looked through the code, and I can see where it write the filenam-.res file ( "filenam" being the name of the input file), but I cannot find where it needs to open it, presumably for the plotting of the results?

This is a code I received and it works on other computers. I loaded the R program as an administrator to ensure no permissions problems.

The code asks me to give the file name and one value, then the whole process goes to completion with three graphs and a result file.
The result file cannot be opened with permission denied but I am not sure why it needs to open that file as it is a simple text file with the results. I am not sure whether it wants to open it to show the results. Three graphs should normally be produced but they do not appear.
I am concerned about that "permission denied". This is on my own computer so there is no IT restriction.
I am also wondering why I cannot get the graphs either.
I am using R-3.0.2.
When I run it with R studio, I do not get that message and it runs to completion, but there are again no graphs appearing!
I hope you can make sense out of this very frustrating "denied access".
Ok, I was not able to reproduce the error (but I do not run the same R version).

But, as long as I can see, the script does not produce any graphics directly on your screen, but it produce a postscript (.ps) file, together with the .res file. The .res file is only written once. It is not read in again.

Please try the following:
1) Put your source data file (for which the script prompts at the beginning) together with the script file into one single directory, where you have write access. The best would be to create a new directory like C:\temp

2) Start your R environment (not the script yet). You should start on the R console with a prompt. Nothing done yet.

3) Enter at the R prompt:

Open in new window

This is your directory you created at step 1)

4) To run your script enter at the R prompt:

Open in new window

Or the filename your R script is named (I took code1.txt from your attachment here).

5) Enter your source data file at the scripts prompt and all the other questions.

When the script is finished, you should have a .res and .ps file in C:\temp and, hopefully, no error occurs. The .ps file is postscript and contains your graphics. I was able to open it with ghostscript.

If it is still the same I will install R 3.0.2 to check that.

Are you in Windows or Linux environment?


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Daniele QuestiauxResearch associateAuthor Commented:

That is a lesson I wil remember!
The code and the file where n different folders.
 I would use the File>source R(code) to get the code, but it was in a different folder than the file which was in the folder I had set via the File> change dir. OK, the source code and the files need to be together!

For the .ps file, is there a way for me to add a line of code so they could be displayed?
I will start a new thread for that one
Many many thanks! This was driving me mad.


PS I use windows 8.
I also installed R-2.14-1 and had had the same issue as with R-3.0.1, but of course, it now works perfectly well.
Daniele QuestiauxResearch associateAuthor Commented:
R is fun to work with, but unforgiving.

Any code not from a package needs to be placed in a working directory together with any file or data you will work with. Simple but not altogether an obvious requirement!

Code and Data must not be in the same directory. When you start R, it may in some working directory, which is not suitable to save data. So, the acual working directory was your problem. When I start R (Windows 7) I am in "C:/Windows/system32". You can print it with getwd().
Putting all together was just to reduce any effects which may be the cause of your problem.

You could link your new question here, so I can find it easily :-)

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.