[R] project path in Rmd (Ivan Calandra)
Howard, Tim G (DEC)
t|m@how@rd @end|ng |rom dec@ny@gov
Thu Apr 2 13:08:21 CEST 2020
You also should be able to reference locations from the 'root' of your project using the here() package.
https://here.r-lib.org/
Best,
Tim Howard
> Date: Thu, 2 Apr 2020 10:21:47 +0100
> From: Rui Barradas <ruipbarradas using sapo.pt>
> To: Ivan Calandra <calandra using rgzm.de>
> Cc: "r-help using r-project.org" <r-help using r-project.org>
> Subject: Re: [R] project path in Rmd
> Message-ID: <09f30516-7af5-fee7-5efd-e6db69c75fb3 using sapo.pt>
> Content-Type: text/plain; charset="utf-8"; Format="flowed"
>
> Hello,
>
> This is not an answer to the original problem, it's about '..'. (And a
> bit more.)
>
> About '..', see if the following sequence of instructions can help.
> Subdirectories '~/tmp' and '~/snap' exist on my PC, change to
> '~/analysis/scripts' or to what makes sense on yours.
>
> od <- getwd() # save this for later
>
> setwd('~/tmp') #
> list.files('../snap') # goes up one level and
> # executes a SO/files related command
> curr <- getwd()
> basename(curr) # these two instructions are meant to show that
> dirname(curr) # you don't need to know how many levels you have
> # to go up, you can parse 'curr' if basename and
> # dirname are not enough
>
> setwd(od) # back to where I was
>
>
> Hope this helps,
> Rui Barradas
> Às 10:02 de 02/04/20, Ivan Calandra escreveu:
> I do not know this ".." command (could you please show me how to use it
> in a relative path?), but it sounds like a good start.
>
> But it implies that I know in advance how many folders up the parent
> directory is. I guess in most cases it will always be the same, but it
> would be even better if it could be applied generically.
>
> As I said, ideally, I would like to get the project directory from a
> script located in a subfolder.
>
> Thanks!
> Ivan
>
> --
> Dr. Ivan Calandra
> TraCEr, laboratory for Traceology and Controlled Experiments
> MONREPOS Archaeological Research Centre and
> Museum for Human Behavioural Evolution
> Schloss Monrepos
> 56567 Neuwied, Germany
> +49 (0) 2631 9772-243
> https://www.researchgate.net/profile/Ivan_Calandra
>
> On 02/04/2020 10:54, Ivan Krylov wrote:
>> On Thu, 2 Apr 2020 10:30:29 +0200
>> Ivan Calandra <calandra using rgzm.de> wrote:
>>
>>> The problem I then have is to specify the path for 'raw_data' and
>>> 'derived_data' <...> And these folders are not subfolders of
>>> the working directory '~/analysis/scripts'.
>>
>>> I would like to avoid absolute paths of course
>> Is there a reason to avoid relative paths built using '..' to access
>> parent directories?
>>
>
More information about the R-help
mailing list