Does the R plugin work?

In Xubuntu 20.10 I get the error

Installing package into `/usr/local/lib/R/site-library'
(as `lib' is unspecified)
Warning in install.packages(pack, repos = NULL, type = "source") :
  'lib = "/usr/local/lib/R/site-library"' is not writable
Error: ERROR: no packages specified

Does anyone know how to make it work?
Edit: it could help, as someone in Hacker News says they want to try it :slight_smile:

R by default doesn’t utilize a personal library if it doesn’t exist (it won’t be in the paths), but when you attempt to install a package if the first library is found not writeable it will ask you to create a personal library at ~/R/%p-library/%v (e.g. ~/R/x86_64-pc-linux-gnu-library/4.0). If this directory exists, even if empty, R will pick it up.

The problem is that it tries to install the TeXmacs package in the system-wide library which is expected behavior if you’ve never installed any R package before. If you make the previous directory, it should fix it.

Alternatively, you can explicitly set a path to user library by setting R_LIBS_USER in ~/.Renviron. Either one of the previous, or if you don’t want extra folders in home

R_LIBS_USER=~/.local/lib/R

and then doing mkdir -p ~/.local/lib/R.

1 Like

Thanks, I have tested the solution with

R_LIBS_USER=~/.local/lib/R

and despite that there is still an error message

The following object is masked from `package:utils':

    ?

Error: ERROR: no packages specified

it is possible to enter commands and see the output—I am going to link to this answer in the HN thread.

Is this persistent error appearing everytime you start a session or only appears during first-time run?

I have opened two sessions so far and it appeared in both. It did not affect the commands that I tried but I tried a few simple ones.

A separate thing that would be good for the plugin would be to have the possibility to embed plots (maybe there is, but I did not yet investigate enough).
In the Python plugin as far as I know this is achieved by having the plot saved as pdf and then read into the document.
If we don’t know of any way of doing this I could report having embedded plots as a wish on the bug tracker in Savannah—and I would report the error message as well.

If you’re feeling adventurous you can try it in the experimental Jupyter plugin with the IRkernel :wink:

1 Like

The help for the R plugin shows that it should work in that plugin by using v():

The v() function can be used in order to include the contents of the R graphics window inside your worksheet.

Actually plots embedding works fine and the workflow is close to R console. After doing a plot as you say, a new window with the plot opens. For example

t=seq(0,10,0.1)
y=sin(t)
plot(t,y,type="l",xlab="t",ylab="sin(t)")

Then you can build it step-by-step, such as doing

title("sin(t)")
legend("bottomright",legend=c("sin(t)"),lty=1:2,cex=0.8)

After having your graph, you can embed it with

v()

You can close the window programmatically with

dev.off()

Edit: Oh, you found it.

1 Like

@jeroen found it, I did not make the effort of reading the help :slight_smile:

Is this solution valid for Windows as well?

I cannot make R work in TeXmacs: every time I insert a new session the plug-in gets started but stucks with a message of “Busy…” and does nothing more.

Does anybody else find this issue?

Hi @imateos and welcome to the forum.
The R plugin under Windows doesn’t work for me either.
I have looked very quickly at the initialization code for the R plugin and there are :winpath commands, which as far as I understand indicate that who wrote it wanted to make it work under Windows as well.
I will have time to look at the code with more calm next week - I never tried to get a plugin running under Windows so it might take a while before I figure out how-to.
But maybe someone else can be quicker than me.

Giovanni

1 Like

The first thing to check is where the executable is installed and then whether TeXmacs can find it. If these checks pass then there could be a problem with the initialisation code.

The fact that the session appears at all would indicate that the executable is found in the path.

Could you restart TeXmacs, enable “Tools -> Debugging tool”, then enable “Debug -> io” and start a session? Then go to “Debug -> Consoles -> Debugging consoles” to see the debugging output.

I get

Error: cannot start 'tm_r'

By the way, I find it inconvenient that I cannot copy from the debugging console—I will place a feature request in Savannah :wink:

Said this, I do not understand the interaction between the various components, there is R code (texmacs.r) and C code (tm_r.c), I assume tm_r.c is the tm_r that appeats in the console: but is it part of TeXmacs or part of R? And should there be a compiled tm_r code?

Hi
I don`t know if this helps, but i have noticed that tm_r is not on /texmac/plugins/r/bin on github.
I happen to have it in my local copy in widows. However i have tried to compile the file by opening command line, pointing to the plugins/r directory where Cmake is, then launching make and and this is the result:

make
gcc -I…/…/src/System src/tm_r.c -o bin/tm_r -lutil
src/tm_r.c:11:10: fatal error: config.h: No such file or directory
#include “config.h”
^~~~~~~~~~
compilation terminated.
make: *** [Makefile:17: bin/tm_r] Error 1

I guess that something is incomplete in C instalation and does not allow to compile or even the compiled file tm_r is not operative.

My expertise on C is limited, however this is what i have noticed so far

Regards

Pedro

Thanks for looking into this @Pdiazs.

To compile tm_r with cmake, you create a build directory in the main TeXmacs source directory, then do cmake .. from that subdirectory and “make tm_r”. Cmake configures a make target for tm_r in the build directory, not in the source directory. Any Makefiles in the source directory are likely from the autotools build system.

In my system the compiled binary tm_r then gets installed in /usr/share/TeXmacs/plugins/r/bin/tm_r. It should be compiled and installed on Windows, too. If it isn’t, we need to look into why.

I have not succeeded in executing your instructions (perhaps I did not understand them) so I adapted them in a way that I thought sensible:

  • I created the build directory in the /plugins/r` directory
  • I run cmake .. -G "MinGW Makefiles" using PowerShell (btw with two dots only, I think there you have one dot too many) to tell cmake that it has to configure the build for MinGW; this generates a Makefile in the build directory, that has a rule for tm_r
  • I run make tm_r in the build directory

When I do that, I expect minGW to generate an executable file or stop with errors, but neither happens. I get instead

Microsoft Windows [Version 10.0.19041.985]
(c) Microsoft Corporation. Alle Rechte vorbehalten.

And no other output.

After that, I cannot find a tm_r executable anywhere.

By the way, I do not understand how the linker can find config.h (first included header, line 11)

The CMakeLists.txt file in the plugins/r directory makes use of variables set up by the top level CMakeLists.txt. If you call Cmake on the subdirectory, it will not work. You need to go to the directory of the topmost CMakeLists.txt (this one ), create a build subdirectory, go into it and call cmake .. from there.

Anyway, the first thing to figure out is whether there is a compiled binary in the distributed TeXmacs package. If you install TeXmacs from texmacs.org, does it install tm_r?

Thanks for the explanation. Then I have to figure out how to use QT under MinGW (point where cmake stops at the moment).
Will write when I make progress.
G.

It does not seems so (I’ve verified in my virtual machine). Maybe there is a bug in the installer.

2 Likes