Do you usually start R with a desktop icon or some other shortcut? Are you tired of using
setwd
and getwd
each time after you start R to get the working directory correctly? If so, then your days of suffering might be just coming to an end.
Having the working directory set correctly is very convenient. You can both read and write files to the proper place without typing (on Windows, usually very long) path names. There are couple of solutions:
- Use
setwd
in scripts.One way to achieve this is to have asetwd
function call at the top of your scripts. You then run it every time you do the computations in that script. For example to have at the top of a file a following line:
setwd("c:/path/to/my/directory/")
It is a nice approach, but things get complicated if you move files to different computers, say from home to your office, and have different directory structures, disk names etc. Of course you can change it every time. Or perhaps keep couple of versions and have all of them but one commented, for example:
# setwd("c:/path/to/my/directory/at/home") setwd("c:/path/to/my/directory/at/work")
Which is also OK, but for me is too much micromanagement. Also, it becomes a problem if the script is not intended for interactive use.
댓글 없음:
댓글 쓰기