From hb at biostat.ucsf.edu  Fri Jan 11 21:22:21 2013
From: hb at biostat.ucsf.edu (Henrik Bengtsson)
Date: Fri, 11 Jan 2013 12:22:21 -0800
Subject: [Rd] Patch for setwd() to show path in error message
Message-ID: <CAFDcVCSbs3nh_Lnc8xi0RhHpL4WS=QpSakyD+ERyUU7nv-H68Q@mail.gmail.com>

Below is a patch for setwd() to show path in error message.  Current
it just gives error messages such as:

Error in setwd(libdir) : cannot change working directory

with the patch it should (read untested) give:

Error in setwd(libdir) : cannot change working directory to 'path/that/fails/'


PATCH:

% diff -u util.c "util,patch.c"

--- util.c      2012-12-16 13:13:05.002249900 -0800
+++ util,patch.c        2013-01-11 11:52:16.843236400 -0800
@@ -696,14 +696,14 @@
     {
        const wchar_t *path = filenameToWchar(STRING_ELT(s, 0), TRUE);
        if(_wchdir(path) < 0)
-           error(_("cannot change working directory"));
+         error(_("cannot change working directory to '%s'"), path);
     }
 #else
     {
        const char *path
            = R_ExpandFileName(translateChar(STRING_ELT(s, 0)));
     if(chdir(path) < 0)
-       error(_("cannot change working directory"));
+      error(_("cannot change working directory to '%s'"), path);
     }
 #endif
     return(wd);


TRANSLATIONS:
I have zero experience with GNU gettext/*.po files, but I understand
that the above change requires updates to src/library/base/*.po files,
which now looks like (e.g. de.po):

#: src/main/util.c:699 src/main/util.c:706
msgid "cannot change working directory"
msgstr "kann Arbeitsverzeichnis nicht wechseln"

A generic/automatic update would be to use the format:

#: src/main/util.c:699 src/main/util.c:706
msgid "cannot change working directory: '%s'"
msgstr "kann Arbeitsverzeichnis nicht wechseln: '%s'"

but I don't think that is in line with the current R style.

/Henrik

PS. Background for this patch:
https://r-forge.r-project.org/tracker/index.php?func=detail&aid=2395&group_id=34&atid=194



[Rd] Patch for setwd() to show path in error message
Henrik Bengtsson