Re: [R] Problem with R coding

2024-03-12 Thread Ivan Krylov via R-help
В Tue, 12 Mar 2024 14:57:28 +
CALUM POLWART  пишет:

> That's almost certainly going to be either the utf-8 character in the
> path

The problem, as diagnosed by Maria in the first post of the thread, is
that the user home directory as known to R is stored in the ANSI
encoding instead of UTF-8, despite the session charset should be UTF-8
as Maria's Windows is sufficiently new [*]. As soon as any bit of R
tries to perform an encoding conversion using this path (for example,
file.exists() converting it from UTF-8 to UCS-2 in order to interact
with Windows filesystem APIs), the conversion fails. Since tcltk2 uses
file.exists('~/...') in its .onLoad, the package and any of its hard
dependencies are now broken.

Normally, this path is determined automatically to be something like
C:\Users\username\Documents. With OneDrive taking over, it turns out to
be something else and for some reason in the wrong encoding (ANSI but
marked as native == UTF-8).

The function that determines this path lives in src/gnuwin32/shext.c
(char *getRUser(void)). It starts by looking at the environment
variable R_USER, which is why in order to override OneDrive, the user
has to set it first (in the command line or system settings). If that
fails, R tries the environment variable HOME (which is usually set on
Windows, isn't it?), consults SHGetKnownFolderPath(FOLDERID_Documents)
(which returns the result as a wchar_t[] to be manually converted to
UTF-8 by R), consults a few more environment variables, and finally
tries to use the current directory. There is likely no easy way to use
`subst` to give a different home drive to R.

If I set %HOME% or even %R_USER% to a non-ASCII path without setting up
OneDrive, R works normally, so getenv() must be able to return
UTF-8-encoded variables. I don't see how ShellGetPersonalDirectory()
could fail in this manner. My remaining hypothesis is that OneDrive
somehow causes getenv("HOME") to return "C:\\Users\\marga\\OneDrive
- Fundación Universitaria San Pablo CEU\\Documentos" in ANSI instead of
UTF-8.

If anyone here has OneDrive set up in this manner and can debug R,
a trace of what getRUser() actually does would be very useful.

-- 
Best regards,
Ivan

[*]
https://blog.r-project.org/2020/05/02/utf-8-support-on-windows/index.html
https://blog.r-project.org/2022/11/07/issues-while-switching-r-to-utf-8-and-ucrt-on-windows/index.html

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Problem with R coding

2024-03-12 Thread Iris Simmons
Hi Maria,


I had something similar on my Windows work laptop at some point where the
home directory was something containing non ASCII characters. The easy
solution is to copy said directly from the file explorer into
utils::shortPathName, and then set that as the home directory. In my case,

> writeLines(utils::shortPathName(r"(C:\Users\iris\OneDrive - Organization
Name Non ASCII\Documents)"))
C:\Users\iris\ONEDRI~1\DOCUME~1

and then in the control panel, then user accounts (twice), then Change My
Environment Variables, enter the variable name HOME and the directory that
was produced by R. Now the HOME directory contains all ASCII characters so
everything works as expected.


I hope this helps!



On Tue, Mar 12, 2024, 04:49 Maria Del Mar García Zamora <
mar.garc...@alumnos.uchceu.es> wrote:

> Hello,
>
> This is the error that appears when I try to load library(Rcmdr). I am
> using R version 4.3.3. I have tried to upload the packages, uninstall them
> and intalling them again and nothing.
> Loading required package: splines
> Loading required package: RcmdrMisc
> Loading required package: car
> Loading required package: carData
> Loading required package: sandwich
> Loading required package: effects
> lattice theme set by effectsTheme()
> See ?effectsTheme for details.
> Error: package or namespace load failed for ‘Rcmdr’:
>  .onLoad failed in loadNamespace() for 'tcltk2', details:
>   call: file.exists("~/.Rtk2theme")
>   error: file name conversion problem -- name too long?
>
> Once this appears I use path.expand('~') and this is R's answer:
> [1] "C:\\Users\\marga\\OneDrive - Fundaci\xf3n Universitaria San Pablo
> CEU\\Documentos"
>
> The thing is that in spanish we use accents, so this word (Fundaci\xf3n)
> really is Fundación, but I can't change it.
>
> I have tried to start R from CDM using: C:\Users\marga>set
> R_USER=C:\Users\marga\R_USER
>
> C:\Users\marga>"C:\Users\marga\Desktop\R-4.3.3\bin\R.exe" CMD Rgui
>
> At the beginning this worked but right now a message saying that this app
> cannot be used and that I have to ask the software company (photo attached)
>
> What should I do?
>
> Thanks,
>
> Mar
>
>
> [https://www.uchceu.es/img/externos/correo/ceu_uch.gif]<
> https://www.uchceu.es/>
>
> Maria Del Mar García Zamora
> Alumno UCHCEU -
> Universidad CEU Cardenal Herrera
> -
> Tel.
> www.uchceu.es
>
> [https://www.uchceu.es/img/logos/wur.jpg]
> [https://www.uchceu.es/img/externos/correo/medio_ambiente.gif] Por favor,
> piensa en el medio ambiente antes de imprimir este contenido
>
>
>
> [http://www.uchceu.es/img/externos/correo/ceu_uch.gif]<
> http://www.uchceu.es/>
>
> Maria Del Mar García Zamora
>
> www.uchceu.es
>
> [http://www.uchceu.es/img/externos/correo/medio_ambiente.gif] Por favor,
> piensa en el medio ambiente antes de imprimir este contenido
>
>
>
>
> Este mensaje y sus archivos adjuntos, enviados desde FUNDACIÓN
> UNIVERSITARIA SAN PABLO-CEU, pueden contener información confidencial y
> está destinado a ser leído sólo por la persona a la que va dirigido, por lo
> que queda prohibida la difusión, copia o utilización de dicha información
> por terceros. Si usted lo recibiera por error, por favor, notifíquelo al
> remitente y destruya el mensaje y cualquier documento adjunto que pudiera
> contener. Cualquier información, opinión, conclusión, recomendación, etc.
> contenida en el presente mensaje no relacionada con la actividad de
> FUNDACIÓN UNIVERSITARIA SAN PABLO-CEU, y/o emitida por persona no
> autorizada para ello, deberá considerarse como no proporcionada ni aprobada
> por FUNDACIÓN UNIVERSITARIA SAN PABLO-CEU, que pone los medios a su alcance
> para garantizar la seguridad y ausencia de errores en la correspondencia
> electrónica, pero no puede asegurar la inexistencia de virus o la no
> alteración de los documentos transmitidos electrónicamente, por lo que
> declina cualquier responsabilidad a este respecto.
>
> This message and its attachments, sent from FUNDACIÓN UNIVERSITARIA SAN
> PABLO-CEU, may contain confidential information and is intended to be read
> only by the person it is directed. Therefore any disclosure, copying or use
> by third parties of this information is prohibited. If you receive this in
> error, please notify the sender and destroy the message and any attachments
> may contain. Any information, opinion, conclusion, recommendation,...
> contained in this message and which is unrelated to the business activity
> of FUNDACIÓN UNIVERSITARIA SAN PABLO-CEU and/or issued by unauthorized
> personnel, shall be considered unapproved by FUNDACIÓN UNIVERSITARIA SAN
> PABLO-CEU. FUNDACIÓN UNIVERSITARIA SAN PABLO-CEU implements control
> measures to ensure, as far as possible, the security and reliability of all
> its electronic correspondence. However, FUNDACIÓN UNIVERSITARIA SAN
> PABLO-CEU does not guarantee that emails are virus-free or that documents
> have not be altered, and does not take responsibility in this 

Re: [R] Problem with R coding

2024-03-12 Thread CALUM POLWART
That's almost certainly going to be either the utf-8 character in the path
OR the use of one drive which isn't really a subfolder as I understand it.

When I've had these issues in the past, I've been able to mount a drive
(say U:/ ) which sites further down /up the folder tree so that R just
called "U:/RCodeFolder/Rfile.R"

Is that possible with an C drive?

On Tue, 12 Mar 2024, 10:40 Ivan Krylov via R-help, 
wrote:

> Dear Maria,
>
> I'm sorry for somehow completely missing the second half of your
> message where you say that you've already tried the workaround.
>
> В Tue, 12 Mar 2024 07:43:08 +
> Maria Del Mar García Zamora  пишет:
>
> > I have tried to start R from CDM using: C:\Users\marga>set
> > R_USER=C:\Users\marga\R_USER
> >
> > C:\Users\marga>"C:\Users\marga\Desktop\R-4.3.3\bin\R.exe" CMD Rgui
> >
> > At the beginning this worked but right now a message saying that this
> > app cannot be used and that I have to ask the software company (photo
> > attached)
>
> Glad to know the workaround helped. It sounds like your Windows
> 10 is set up in a user-hostile way.
>
> It may help to visit the Windows Security settings and make an
> exception for C:\Users\marga\Desktop\R-4.3.3\bin\R.exe. An approximate
> instruction can be found at
> , but it
> might be the case that your university IT must take a look at it before
> allowing you to run R on your computer.
>
> Feel free to disregard this advice if someone with more Windows
> experience shows up.
>
> --
> Best regards,
> Ivan
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Problem with R coding

2024-03-12 Thread Ivan Krylov via R-help
Dear Maria,

I'm sorry for somehow completely missing the second half of your
message where you say that you've already tried the workaround.

В Tue, 12 Mar 2024 07:43:08 +
Maria Del Mar García Zamora  пишет:

> I have tried to start R from CDM using: C:\Users\marga>set
> R_USER=C:\Users\marga\R_USER
> 
> C:\Users\marga>"C:\Users\marga\Desktop\R-4.3.3\bin\R.exe" CMD Rgui  
> 
> At the beginning this worked but right now a message saying that this
> app cannot be used and that I have to ask the software company (photo
> attached)

Glad to know the workaround helped. It sounds like your Windows
10 is set up in a user-hostile way.

It may help to visit the Windows Security settings and make an
exception for C:\Users\marga\Desktop\R-4.3.3\bin\R.exe. An approximate
instruction can be found at
, but it
might be the case that your university IT must take a look at it before
allowing you to run R on your computer.

Feel free to disregard this advice if someone with more Windows
experience shows up.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Problem with R coding

2024-03-12 Thread Ivan Krylov via R-help
В Tue, 12 Mar 2024 07:43:08 +
Maria Del Mar García Zamora  пишет:

> Error: package or namespace load failed for ‘Rcmdr’:
>  .onLoad failed in loadNamespace() for 'tcltk2', details:
>   call: file.exists("~/.Rtk2theme")
>   error: file name conversion problem -- name too long?
> 
> Once this appears I use path.expand('~') and this is R's answer:
> [1] "C:\\Users\\marga\\OneDrive - Fundaci\xf3n Universitaria San
> Pablo CEU\\Documentos"

We've seen this problem before:
https://stat.ethz.ch/pipermail/r-help/2023-December/478732.html

The workaround that should help is to set the R_USER environment
variable to C:\Users\marga before launching R.

Please let me know if you're willing to debug R. (This will likely
involve compiling R from source with debugging symbols enabled and
stepping through the code.) There are no places in the Windows code
where R gets the conversion obviously wrong. I don't have OneDrive and I
wasn't able to convince R to return an invalid R_USER path without it.
I'm halfway convinced this is due to a bug in OneDrive itself.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Problem with R coding

2024-03-12 Thread Rui Barradas

Às 07:43 de 12/03/2024, Maria Del Mar García Zamora escreveu:

Hello,

This is the error that appears when I try to load library(Rcmdr). I am using R 
version 4.3.3. I have tried to upload the packages, uninstall them and 
intalling them again and nothing.
Loading required package: splines
Loading required package: RcmdrMisc
Loading required package: car
Loading required package: carData
Loading required package: sandwich
Loading required package: effects
lattice theme set by effectsTheme()
See ?effectsTheme for details.
Error: package or namespace load failed for ‘Rcmdr’:
  .onLoad failed in loadNamespace() for 'tcltk2', details:
   call: file.exists("~/.Rtk2theme")
   error: file name conversion problem -- name too long?

Once this appears I use path.expand('~') and this is R's answer:
[1] "C:\\Users\\marga\\OneDrive - Fundaci\xf3n Universitaria San Pablo 
CEU\\Documentos"

The thing is that in spanish we use accents, so this word (Fundaci\xf3n) really 
is Fundación, but I can't change it.

I have tried to start R from CDM using: C:\Users\marga>set 
R_USER=C:\Users\marga\R_USER

C:\Users\marga>"C:\Users\marga\Desktop\R-4.3.3\bin\R.exe" CMD Rgui

At the beginning this worked but right now a message saying that this app 
cannot be used and that I have to ask the software company (photo attached)

What should I do?

Thanks,

Mar


[https://www.uchceu.es/img/externos/correo/ceu_uch.gif]

Maria Del Mar García Zamora
Alumno UCHCEU -
Universidad CEU Cardenal Herrera
-
Tel.
www.uchceu.es

[https://www.uchceu.es/img/logos/wur.jpg]
[https://www.uchceu.es/img/externos/correo/medio_ambiente.gif] Por favor, 
piensa en el medio ambiente antes de imprimir este contenido



[http://www.uchceu.es/img/externos/correo/ceu_uch.gif]

Maria Del Mar García Zamora

www.uchceu.es

[http://www.uchceu.es/img/externos/correo/medio_ambiente.gif] Por favor, piensa 
en el medio ambiente antes de imprimir este contenido




Este mensaje y sus archivos adjuntos, enviados desde FUNDACIÓN UNIVERSITARIA 
SAN PABLO-CEU, pueden contener información confidencial y está destinado a ser 
leído sólo por la persona a la que va dirigido, por lo que queda prohibida la 
difusión, copia o utilización de dicha información por terceros. Si usted lo 
recibiera por error, por favor, notifíquelo al remitente y destruya el mensaje 
y cualquier documento adjunto que pudiera contener. Cualquier información, 
opinión, conclusión, recomendación, etc. contenida en el presente mensaje no 
relacionada con la actividad de FUNDACIÓN UNIVERSITARIA SAN PABLO-CEU, y/o 
emitida por persona no autorizada para ello, deberá considerarse como no 
proporcionada ni aprobada por FUNDACIÓN UNIVERSITARIA SAN PABLO-CEU, que pone 
los medios a su alcance para garantizar la seguridad y ausencia de errores en 
la correspondencia electrónica, pero no puede asegurar la inexistencia de virus 
o la no alteración de los documentos transmitidos electrónicamente, por lo que 
declina cualquier responsabilidad a este respecto.

This message and its attachments, sent from FUNDACIÓN UNIVERSITARIA SAN 
PABLO-CEU, may contain confidential information and is intended to be read only 
by the person it is directed. Therefore any disclosure, copying or use by third 
parties of this information is prohibited. If you receive this in error, please 
notify the sender and destroy the message and any attachments may contain. Any 
information, opinion, conclusion, recommendation,... contained in this message 
and which is unrelated to the business activity of FUNDACIÓN UNIVERSITARIA SAN 
PABLO-CEU and/or issued by unauthorized personnel, shall be considered 
unapproved by FUNDACIÓN UNIVERSITARIA SAN PABLO-CEU. FUNDACIÓN UNIVERSITARIA 
SAN PABLO-CEU implements control measures to ensure, as far as possible, the 
security and reliability of all its electronic correspondence. However, 
FUNDACIÓN UNIVERSITARIA SAN PABLO-CEU does not guarantee that emails are 
virus-free or that documents have not be altered, and does not take 
responsibility in this respect.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Hello,

First of all, try running Rgui only, no R.exe CMD. Just Rgui.exe or
C:\Users\marga\Desktop\R-4.3.3\bin\Rgui.exe
Then, in Rgui, try loading Rcmdr

library(Rcmdr)


Also, do you have R in your Windows PATH variable? The directory to put 
in PATH should be


C:\Users\marga\Desktop\R-4.3.3\bin

so that Windows can find R.exe and Rgui.exe without the full path name.

Hope this helps,

Rui Barradas



--
Este e-mail foi analisado pelo software antivírus AVG para verificar a presença 
de vírus.
www.avg.com
__