SQL Server 2022 named instance and machine learning

I've installed SQL Server 2022 (EE RTM and with CU7) and machine learning on a default instance without any problem. Installing it on a named instance runs fine as well. (R 4.2.0 and R 4.2.3) But when I run my test statement there are warnings on the named instance.

The issue  

EXEC sp_execute_external_script @language =N'R', @script=N'print("Hello World from R")';

The result is not only the message, but some warnings (BTW very interesting the german word "Warnmeldung" eq. "Warning" on a system I thought to be installed in english)

STDERR message(s) from external script: 
Warnmeldung:
In normalizePath(path.expand(path), winslash, mustWork) :
  path[1]="C:/ProgramData//R/library": Access is denied
Warnmeldung:
package "methods" in options("defaultPackages") was not found 
STDOUT message(s) from external script: 
[1] "Hello World from R"

All services are using the same dedicated domain account. Using the managed service accounts makes no difference.
Using ProcessMonitor it looks like rterm.exe is trying to create a file in C:\ProgramData instead of C:\ProgramData\<instancename>. The result is “ACCESS DENIED”.
When tracing the default instance rterm.exe is using C:\ProgramData\MSSQLSERVER to create a file. The result is “SUCCESS”.

I’ve discussed this with Erland Sommarskog here: How to install machine learning on SQL Server 2022 named instance? - Microsoft Q&A

The workaround  

The workaround is to provide full access to MSSQLLaunchapd$<instancename> (Launchpad account) and "All application packages" to C:\programdata folder.
After a restart of the launchpad service, everything is working as expected.

In my opinion there can be a security issue if you have more than one named instance on a server with machine learning, because they would share the folder c:\programdata.

The solution  

There will be a fix in an upcoming CU which should include using the correct subfolder instead of setting the permissions.

But you should keep in mind that you have to clean up your installation if you have already applied the workaround.

I believe that we have to uninstall R/Python first. Remove the wrong permissions and apply the CU.
Then install R/Python again. I will do this for fun on my test box.
However, I will wait until the CU is available, before upgrading to SQL Server 2022 on my BI machines.
Hopefully, with the CU they use the correct subfolders for each instance, instead of messing up c:\programdata.