[Rd] How is the environment variable "R_USER" defined?

2021-11-22 Thread Jiefei Wang
Hi, I have a new win system and try to install R as usual. Somehow,
the environment variable "R_LIBS_USER" is incorrectly pointed to a
Onedrive folder. Since "R_LIBS_USER" depends on "R_USER", the root
problem then becomes why "R_USER" is the path to the Onedrive. I did
an exhausting search in the R directory and the only related message I
can find is from EnvVar.html, which states

R_USER: The user's ‘home’ directory. Set by R. (HOME will be set to
the same value if not already set.)

I guess that's another way to say "no document is available yet". I
also took a look at my system environment variables but there are only
two variables related to Onedrive, they are

OneDrive=C:\Users\wangj\OneDrive

OneDriveConsumer=C:\Users\wangj\OneDrive

so everything looks pretty normal, I know I can correct this issue by
manually adding Renviron but I just wonder where this default behavior
comes from...

Best,
Jiefei

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] meaning of browser(skipCalls=)

2021-11-22 Thread Frederick Eaton

Dear R Devel,

I have been advised to use "options(error=recover)" to enable
debugging on errors. But sometimes it would seem more convenient to
override "stopifnot", for example:

stopifnot = function(b) { if(!b) { browser(skipCalls=1); } }

However, this doesn't do what I expected. On looking closer I find
that the "skipCalls" argument seems to be ignored except when printing
the "Called from: " message; it does not affect the evaluation context
or the output of 'where':

> var=2; f=function(){var=1; browser(skipCalls=0)}; f()
Called from: f()
Browse[1]> var
[1] 1
Browse[1]> where
where 1: f()

Browse[1]> Q
> var=2; f=function(){var=1; browser(skipCalls=1)}; f()
Called from: top level 
Browse[1]> var

[1] 1
Browse[1]> where
where 1: f()

Browse[1]> Q
> var=2; f=function(){var=1; browser(skipCalls=2)}; f()
Called from: top level 
Browse[1]> var

[1] 1
Browse[1]> where
where 1: f()

Browse[1]> Q

So it appears that the "browser()" API does not actually make it
possible to call this built-in function from within another R function
and thereby emulate the same behavior as calling browser() directly.

If this is the case, it might be good to have it fixed or documented.
I am aware of "browser(expr=)", but this requires editing the
particular call that failed. The documentation for "browser()" led me
to hope that my use case would be supported, if only because it admits
that users might want to build other debugging functions with
browser(): "The 'skipCalls' argument should be used when the
'browser()' call is nested within another debugging function". An
example where this 'skipCalls' parameter is used to build a useful
debugging function would help to clarify its English description in
the manual.

Also, from the browser() command line I could not find a way to step
*out* of the current function. This would have been a way to recover
from skipCalls not working as expected. Am I missing something? For
example is there some command other than "n", where the below
interaction could pause before "hi" and "bye"?

> f=function(){browser(); message("in f"); message("out f")}; f(); message("hi"); 
message("bye")
Called from: f()
Browse[1]> n
debug at #1: message("in f")
Browse[2]> n
in f
debug at #1: message("out f")
Browse[2]> n
out f
hi
bye

If it is not possible for the R debugger to step out of a function, it
would be good to document that too, maybe after the list of browser
prompt commands in "?browser". Being confined within a single function
is not an obvious disability for a debugger to have.

I feel that R is an excellent tool, but sometimes I think that if the
shortcomings of the system were better documented, then this would
save users a lot of time in certain cases.

Thank you,

Frederick

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] How is the environment variable "R_USER" defined?

2021-11-22 Thread Duncan Murdoch

On 22/11/2021 11:46 a.m., Jiefei Wang wrote:

Hi, I have a new win system and try to install R as usual. Somehow,
the environment variable "R_LIBS_USER" is incorrectly pointed to a
Onedrive folder. Since "R_LIBS_USER" depends on "R_USER", the root
problem then becomes why "R_USER" is the path to the Onedrive. I did
an exhausting search in the R directory and the only related message I
can find is from EnvVar.html, which states

R_USER: The user's ‘home’ directory. Set by R. (HOME will be set to
the same value if not already set.)

I guess that's another way to say "no document is available yet". I
also took a look at my system environment variables but there are only
two variables related to Onedrive, they are

OneDrive=C:\Users\wangj\OneDrive

OneDriveConsumer=C:\Users\wangj\OneDrive

so everything looks pretty normal, I know I can correct this issue by
manually adding Renviron but I just wonder where this default behavior
comes from...




I think you want to look at the Windows FAQ. From question 2.14:

The home directory is set as follows: If environment variable R_USER is 
set, its value is used. Otherwise if environment variable HOME is set, 
its value is used. After those two user-controllable settings, R tries 
to find system-defined home directories. It first tries to use the 
Windows "personal" directory (typically C:\Users\username\Documents). If 
that fails, if both environment variables HOMEDRIVE and HOMEPATH are set 
(and they normally are), the value is ${HOMEDRIVE}${HOMEPATH}. If all of 
these fail, the current working directory is used.



Duncan Murdoch

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] How is the environment variable "R_USER" defined?

2021-11-22 Thread Sebastian Meyer

Just a quick thought.
R for Windows FAQ 2.14 talks about the home directory:

https://cran.r-project.org/bin/windows/base/rw-FAQ.html#What-are-HOME-and-working-directories_003f

So maybe HOMEDRIVE and HOMEPATH are involved?

Hope this helps.

Sebastian Meyer


Am 22.11.21 um 17:46 schrieb Jiefei Wang:

Hi, I have a new win system and try to install R as usual. Somehow,
the environment variable "R_LIBS_USER" is incorrectly pointed to a
Onedrive folder. Since "R_LIBS_USER" depends on "R_USER", the root
problem then becomes why "R_USER" is the path to the Onedrive. I did
an exhausting search in the R directory and the only related message I
can find is from EnvVar.html, which states

R_USER: The user's ‘home’ directory. Set by R. (HOME will be set to
the same value if not already set.)

I guess that's another way to say "no document is available yet". I
also took a look at my system environment variables but there are only
two variables related to Onedrive, they are

OneDrive=C:\Users\wangj\OneDrive

OneDriveConsumer=C:\Users\wangj\OneDrive

so everything looks pretty normal, I know I can correct this issue by
manually adding Renviron but I just wonder where this default behavior
comes from...

Best,
Jiefei

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel



__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] How is the environment variable "R_USER" defined?

2021-11-22 Thread Bill Dunlap
Is your C:\Users\yourname\Documents linked to OneDrive (either by your
choice or by some administrator setting a group policy)?  If so, ou could
unlink it using OneDrive's settings dialog.   Or you could set R_USER to
avoid using ...\Documents.

-Bill

On Mon, Nov 22, 2021 at 8:47 AM Jiefei Wang  wrote:

> Hi, I have a new win system and try to install R as usual. Somehow,
> the environment variable "R_LIBS_USER" is incorrectly pointed to a
> Onedrive folder. Since "R_LIBS_USER" depends on "R_USER", the root
> problem then becomes why "R_USER" is the path to the Onedrive. I did
> an exhausting search in the R directory and the only related message I
> can find is from EnvVar.html, which states
>
> R_USER: The user's ‘home’ directory. Set by R. (HOME will be set to
> the same value if not already set.)
>
> I guess that's another way to say "no document is available yet". I
> also took a look at my system environment variables but there are only
> two variables related to Onedrive, they are
>
> OneDrive=C:\Users\wangj\OneDrive
>
> OneDriveConsumer=C:\Users\wangj\OneDrive
>
> so everything looks pretty normal, I know I can correct this issue by
> manually adding Renviron but I just wonder where this default behavior
> comes from...
>
> Best,
> Jiefei
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] How is the environment variable "R_USER" defined?

2021-11-22 Thread Jiefei Wang
Thanks for all your help!! It actually has nothing to do with the
environment variables. The issue is caused by the backup feature in
Onedrive as Bill suggested. I do not know what magic trick Onedrive
uses here but it misadvices R to use its directory, not my local
Document directory. The answer might be from Windows FAQ question 2.14
like Duncan posted

After those two user-controllable settings, R tries to find
system-defined home directories. It first tries to use the Windows
"personal" directory

This is confusing. First, this FAQ is not about how "R_USER" is
defined. Instead, it talks about how we find the home directory from
"R_USER". Second, it still did not answer what is "the Windows
personal directory". I think this is where the issue is. My Document
still has the path "C:\Users\wangj\Documents", but there is a backup
path in "C:\Users\wangj\OneDrive\Documents". Unfortunately, R believes
the latter one is the "personal directory". I hope this can be
clarified a little bit to avoid confusion.

Best,
Jiefei

On Mon, Nov 22, 2021 at 12:32 PM Bill Dunlap  wrote:
>
> Is your C:\Users\yourname\Documents linked to OneDrive (either by your choice 
> or by some administrator setting a group policy)?  If so, ou could unlink it 
> using OneDrive's settings dialog.   Or you could set R_USER to avoid using 
> ...\Documents.
>
> -Bill
>
> On Mon, Nov 22, 2021 at 8:47 AM Jiefei Wang  wrote:
>>
>> Hi, I have a new win system and try to install R as usual. Somehow,
>> the environment variable "R_LIBS_USER" is incorrectly pointed to a
>> Onedrive folder. Since "R_LIBS_USER" depends on "R_USER", the root
>> problem then becomes why "R_USER" is the path to the Onedrive. I did
>> an exhausting search in the R directory and the only related message I
>> can find is from EnvVar.html, which states
>>
>> R_USER: The user's ‘home’ directory. Set by R. (HOME will be set to
>> the same value if not already set.)
>>
>> I guess that's another way to say "no document is available yet". I
>> also took a look at my system environment variables but there are only
>> two variables related to Onedrive, they are
>>
>> OneDrive=C:\Users\wangj\OneDrive
>>
>> OneDriveConsumer=C:\Users\wangj\OneDrive
>>
>> so everything looks pretty normal, I know I can correct this issue by
>> manually adding Renviron but I just wonder where this default behavior
>> comes from...
>>
>> Best,
>> Jiefei
>>
>> __
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] How is the environment variable "R_USER" defined?

2021-11-22 Thread Tomas Kalibera



On 11/22/21 7:06 PM, Jiefei Wang wrote:

Thanks for all your help!! It actually has nothing to do with the
environment variables. The issue is caused by the backup feature in
Onedrive as Bill suggested. I do not know what magic trick Onedrive
uses here but it misadvices R to use its directory, not my local
Document directory. The answer might be from Windows FAQ question 2.14
like Duncan posted

After those two user-controllable settings, R tries to find
system-defined home directories. It first tries to use the Windows
"personal" directory

This is confusing. First, this FAQ is not about how "R_USER" is
defined. Instead, it talks about how we find the home directory from
"R_USER".
My understanding of the text is that R_USER is defined as (one of the) 
environment variable(s) which one can set to override what R understands 
to be the R "home directory"

  Second, it still did not answer what is "the Windows
personal directory". I think this is where the issue is. My Document
still has the path "C:\Users\wangj\Documents", but there is a backup
path in "C:\Users\wangj\OneDrive\Documents". Unfortunately, R believes
the latter one is the "personal directory". I hope this can be
clarified a little bit to avoid confusion.


The "personal directory" is a Windows term. R obtains it via Windows API 
call SHGetSpecialFolderLocation with CSIDL_PERSONAL (which is now My 
Documents), this is why the wording in rw-FAQ:


"It first tries to use the Windows "personal" directory (typically 
@file{C:\Users\username \Documents}).", which gives a typical value.


Best
Tomas




Best,
Jiefei

On Mon, Nov 22, 2021 at 12:32 PM Bill Dunlap  wrote:

Is your C:\Users\yourname\Documents linked to OneDrive (either by your choice 
or by some administrator setting a group policy)?  If so, ou could unlink it 
using OneDrive's settings dialog.   Or you could set R_USER to avoid using 
...\Documents.

-Bill

On Mon, Nov 22, 2021 at 8:47 AM Jiefei Wang  wrote:

Hi, I have a new win system and try to install R as usual. Somehow,
the environment variable "R_LIBS_USER" is incorrectly pointed to a
Onedrive folder. Since "R_LIBS_USER" depends on "R_USER", the root
problem then becomes why "R_USER" is the path to the Onedrive. I did
an exhausting search in the R directory and the only related message I
can find is from EnvVar.html, which states

R_USER: The user's ‘home’ directory. Set by R. (HOME will be set to
the same value if not already set.)

I guess that's another way to say "no document is available yet". I
also took a look at my system environment variables but there are only
two variables related to Onedrive, they are

OneDrive=C:\Users\wangj\OneDrive

OneDriveConsumer=C:\Users\wangj\OneDrive

so everything looks pretty normal, I know I can correct this issue by
manually adding Renviron but I just wonder where this default behavior
comes from...

Best,
Jiefei

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] How is the environment variable "R_USER" defined?

2021-11-22 Thread Duncan Murdoch

On 22/11/2021 1:06 p.m., Jiefei Wang wrote:

Thanks for all your help!! It actually has nothing to do with the
environment variables. The issue is caused by the backup feature in
Onedrive as Bill suggested. I do not know what magic trick Onedrive
uses here but it misadvices R to use its directory, not my local
Document directory. The answer might be from Windows FAQ question 2.14
like Duncan posted

After those two user-controllable settings, R tries to find
system-defined home directories. It first tries to use the Windows
"personal" directory

This is confusing. First, this FAQ is not about how "R_USER" is
defined.


R_USER is an optional environment variable that *you* can set.  If you 
do, it's taken to be the home directory.  If it is not set, the rest of 
the FAQ 2.14 entry is tried.


So if R is coming up with the wrong home directory, the solution is to 
set R_USER to be the directory you want to use.  You have to do this 
before starting R, you can't use Sys.setenv():  it's too late by then.


The easiest way to set an environment variable for R to use is to set it 
in the R_HOME/etc/Renviron.site file.  You can alternatively set it in 
the .Renviron file, but it may be a little mysterious in Windows where 
you should save that.


You can also set environment variables using Windows control panel 
settings, but I don't think I ever learned the details of this for 
Windows 10.  That can be global for all programs for one user, or global 
for all users, depending on how you set it.


Duncan Murdoch

 Instead, it talks about how we find the home directory from

"R_USER". Second, it still did not answer what is "the Windows
personal directory". I think this is where the issue is. My Document
still has the path "C:\Users\wangj\Documents", but there is a backup
path in "C:\Users\wangj\OneDrive\Documents". Unfortunately, R believes
the latter one is the "personal directory". I hope this can be
clarified a little bit to avoid confusion.

Best,
Jiefei

On Mon, Nov 22, 2021 at 12:32 PM Bill Dunlap  wrote:


Is your C:\Users\yourname\Documents linked to OneDrive (either by your choice 
or by some administrator setting a group policy)?  If so, ou could unlink it 
using OneDrive's settings dialog.   Or you could set R_USER to avoid using 
...\Documents.

-Bill

On Mon, Nov 22, 2021 at 8:47 AM Jiefei Wang  wrote:


Hi, I have a new win system and try to install R as usual. Somehow,
the environment variable "R_LIBS_USER" is incorrectly pointed to a
Onedrive folder. Since "R_LIBS_USER" depends on "R_USER", the root
problem then becomes why "R_USER" is the path to the Onedrive. I did
an exhausting search in the R directory and the only related message I
can find is from EnvVar.html, which states

R_USER: The user's ‘home’ directory. Set by R. (HOME will be set to
the same value if not already set.)

I guess that's another way to say "no document is available yet". I
also took a look at my system environment variables but there are only
two variables related to Onedrive, they are

OneDrive=C:\Users\wangj\OneDrive

OneDriveConsumer=C:\Users\wangj\OneDrive

so everything looks pretty normal, I know I can correct this issue by
manually adding Renviron but I just wonder where this default behavior
comes from...

Best,
Jiefei

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel



__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel