2

Possible Duplicate:
Check existence of directory and create if doesn't exist

Is this line of code

if(!file.exists("PLOTS")) dir.create("PLOTS")

equivalent to this line of code?

dir.create('PLOTS',showWarnings=FALSE)

Is there any circumstance in which one will work and the other will not?

Community
  • 1
  • 1
Xu Wang
  • 10,199
  • 6
  • 44
  • 78
  • What is the programming language you are using?? – Sunil Kumar B M Feb 10 '12 at 09:04
  • @SunilKumarBM The OP correctly tagged the question as [tag:r], meaning he is using R. See the tag info for more information. – Andrie Feb 10 '12 at 09:08
  • I updated the title just to make things clearer. – Xu Wang Feb 10 '12 at 09:11
  • 1
    your first line works in Windows too. – tim riffe Feb 10 '12 at 09:19
  • cool, thanks for the confirmation! – Xu Wang Feb 10 '12 at 09:25
  • 1
    also, the second one works just fine in Windows with no side effects. If the folder already exists and has stuff in it, then nothing is done, otherwise one is created. – tim riffe Feb 10 '12 at 09:41
  • good find Chase! I did not find that in my search. However, I am still interested in if these two lines of code are equivalent. Thus, I think my question is different. I will edit my question to clarify that. – Xu Wang Feb 10 '12 at 20:18
  • The two are broadly equivalent. However there exist cases where the `dir.create("PLOTS")` command will fail in the first line and show a warning but the second command will hide any information from the user and still fail. An example would be if a file exists with the same name or if the folder is not writable. See my answer to the possible duplicate for a more robust solution. – zelanix Jan 20 '14 at 00:09

0 Answers0