[R] save at relative directory

Joshua Wiley jwiley.psych at gmail.com
Tue Nov 8 16:22:42 CET 2011


Hi Alex,

For the R part, I would abstract it a bit:

mydir <- paste("./", abs(threshold), sep = "")
if (!file.exists(mydir)) dir.create(mydir)
save(var, file = paste(mydir, DataSource[[4]], sep = "/"))

if you use file.exists('threshold') you are testing for the existence
of threshold, not the value contained in threshold, and anyway, you
seem not not want the value contained in threshold, but the absolute
value of the value in threshold, hence, in part, the value of
abstraction.

In R, see ?unlink for ways to delete things, rmdir looks like you are
using the command prompt, and for that I will refer you to the help
for your OS/shell on how to go about removing unwanted directories
(hint, rmdir --help is not a bad place to start ;)

Cheers,

Josh

On Tue, Nov 8, 2011 at 7:09 AM, Alaios <alaios at yahoo.com> wrote:
> Hmm I will try something like that
>     if (file.exists('threshold')==FALSE)
>       dir.create(paste('./',abs(threshold)))
>
>     save(var,file=paste('./',abs(threshold),'/',DataSource[[4]],sep="")
> I just need a bit of confirmation If I am doing soemthing terribly wrong
> that might harm my filesystem.
> I also did accidentaly
> var<- -13
> dir.create(paste('./',var))
> which created a folder called -13 which I do not know how to remove it
>  rmdir -13
> rmdir: invalid option -- '1'
> Try `rmdir --help' for more information.
>
> B.R
> Alex
>
>
>
> ________________________________
> From: Joshua Wiley <jwiley.psych at gmail.com>
> To: Alaios <alaios at yahoo.com>
> Cc: "R-help at r-project.org" <R-help at r-project.org>
> Sent: Tuesday, November 8, 2011 2:43 PM
> Subject: Re: [R] save at relative directory
>
> Hi Alex,
>
> Look at some of these functions:
>
> apropos("dir")
> apropos("exists")
>
> Cheers,
>
> Josh
>
>
> On Tue, Nov 8, 2011 at 5:36 AM, Alaios <alaios at yahoo.com> wrote:
>> Dear all,
>> I have a variable called thres and before I run a script I set it to a
>> value
>> like
>> thres<- -10
>> at the end of the execution I am issuing a
>> save(variablename,file='Results')
>> which will end up with a file saved at the current directory with the name
>> Results
>>
>> I would like though to use thres value and do the followingg
>> save at the directory called 10 so to get ./10/Results, (yes I want this
>> in a relative order)
>>
>> My question is how I can also check if the directory exists R to create
>> it?
>>
>> I would like to thank you in advance for your help
>>
>> B.R
>> Alex
>>        [[alternative HTML version deleted]]
>>
>>
>> ______________________________________________
>> R-help at r-project.org 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.
>>
>>
>
>
>
> --
> Joshua Wiley
> Ph.D. Student, Health Psychology
> Programmer Analyst II, ATS Statistical Consulting Group
> University of California, Los Angeles
> https://joshuawiley.com/
>
>
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/



More information about the R-help mailing list