Where are the fix() and edit() functions in RStudio Server? - r

I followed the official guide to install RStudio Server. Everything works fine, but the functions, fix and edit, are not available.
For instance, I have a data.frame called "data" as follows.
1,2,3
4,5,6
7,8,9
The command "View(data)" works fine. But when I execute the command "edit(data)" or "fix(data)", it comes some error messages.
The error messages of "fix(data)" :
Error in .External2(C_dataentry, datalist, modes) :
unable to start data editor
In addition: Warning message:
In edit.data.frame(get(subx, envir = parent), title = subx, ...) :
unable to open display
The error message of "edit(data)" :
Error in edit : Editing of data frames and matrixes is not supported in RStudio.
I ran the same codes on my local rstudio (windows 8.1), and all the functions work fine!
It's really wired... Anyone can help me? Thanks a lot!
p.s. I read this post already, but it doesn't work for me.
sessionInfo:
R version 3.1.3 (2015-03-09)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)
locale:
[1] LC_CTYPE=zh_TW.UTF-8 LC_NUMERIC=C LC_TIME=zh_TW.UTF-8
[4] LC_COLLATE=zh_TW.UTF-8 LC_MONETARY=zh_TW.UTF-8 LC_MESSAGES=zh_TW.UTF-8
[7] LC_PAPER=zh_TW.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=zh_TW.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] tools_3.1.3

I had the same problem, but then I installed the XQuartz package from here: https://www.xquartz.org/
And then another thread, from a while back, reminded me that I needed to restart my Mac for the x11 app to take effect: https://stackoverflow.com/a/36486555

Related

Can't install TinyTeX on Windows Server

This is similar to this issue, but the solutions mentioned didn't work for me. I tried to install TinyTeX via different methods:
tinytex::install_tinytex()
download TinyTeX-0.zip, and use tinytex:::install_prebuilt() on it
manually extract TinyTeX-0.zip (unzip() works) and run install-tl-windows (Batch file)
In the first two cases, I have this error:
Error in system2("tlmgr", args, ...) : '"tlmgr"' not found
In addition: Warning message:
In extract(pkg, exdir = path.expand(target)) :
error 1 in extracting from zip file
In the third case, the Windows console looks like this:
'\\crc\users\etienne\Desktop\TinyTeX-0\TinyTeX'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
and then closes without doing anything.
In every case, tinytex::is_tinytex() returns FALSE and tinytex::tlmgr_path() returns nothing.
I am working on Windows Server 2019 Standard (1809). What should I do?
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server x64 (build 17763)
Matrix products: default
locale:
[1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252
[3] LC_MONETARY=French_France.1252 LC_NUMERIC=C
[5] LC_TIME=French_France.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.1.0 tools_4.1.0 tinytex_0.33.1 xfun_0.25
Solved in this GitHub issue
In summary:
run tinytex::install_tinytex(dir = "<path>") where <path> is a local folder on the server, e.g in my case "C:/Users/etienne/TinyTeX"
put options(tinytex.tlmgr.path = tinytex:::find_tlmgr("<path>")) in your .Rprofile (you can easily do that with usethis::edit_r_profile("user"))
restart R
check that tinytex::is_tinytex() is TRUE (you can also try to install a package with tinytex::tlmgr_install("booktabs") for instance)

Shiny Server drops off

I have a shiny server and actually I have been able to upload and use "online" some simple apps, and also the shiny and rmardown test works properly.
But then, when I try to use my own application (which works locally, on my computer), I get the following error message (I looked in log -> var/log/shiny-server):
su: ignore --preserve-environment, it's mutually exclusive to --login.
Loading required package: viridisLite
Loading required package: heatmaply
======================
Welcome to heatmaply version 0.14.1
Type citation('heatmaply') for how to cite the package.
Type ?heatmaply for the main documentation.
The github page is: https://github.com/talgalili/heatmaply/
Please submit your suggestions and bug-reports at: https://github.com/talgalili/heatmaply/issues
Or contact: <tal.galili#gmail.com>
======================
Listening on http://127.0.0.1:43894
Execution halted
The session info:
R version 3.5.0 (2018-04-23)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)
Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=es_ES.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=es_ES.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=es_ES.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=es_ES.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.5.0
I reinstaled both packages, and I also try to call them in R (sudo -i R to use R in console and then library(viridisLite) and library(heatmaply)) and they both works without problem.
When I try to use my App, server gets disconected and I have to restart it (My app starts to charge but when I reach to log issue, stops working)
Maybe the R version has to do with my issue, but I tried to change it unsuccesfully.
Best rewards,
Daniel.
I have installated the last shiny-server version and also went to wired connection -> IPv4-settings and delete the additional DNS server. It works!

R Error in validObject(.Object) when running as script, but not in console

The following code works fine in the R console (R 3.3.0):
m = system.file("external/pores_1.mtx", package = "Matrix")
x = Matrix::readMM(m)
I can put it in a script and it runs fine in R console as:
source("test.R")
However, when I execute it as Rscript --vanilla test.R or Rscript test.R, I get an error:
Error in validObject(.Object) :
invalid class “dgTMatrix” object: Not a valid 'Mnumeric' class object
Calls: <Anonymous> -> new -> initialize -> initialize -> validObject
Execution halted
I don't know if this is related to that specific function. I am guessing this has something to do with how Rscript works, but I used it with various other libraries and functions previously and have never seen anything like this. Any idea what is happening?
I can confirm ... I'm getting the exact same error when running a script containing a call to glmnet(). I was able to trace it back to the Matrix package, on which glmnet depends.
I back-rev'd my R version from v3.3.3 -> v3.3.2 and the error disappeared. I then checked the sessionInfo() between the two and discovered that the version of the Matrix package differed ... it is 1.2-8 (in v3.3.3) and 1.2-7.1 (in v3.3.2). To confirm, I simply replaced the "OK" version of Matrix (7.1) with the "broken" version and the error returned.
I can also confirm that explicitly loading the methods package via library(methods) resolves the error (somehow?), which explains the differing behavior between the console call and the Rscript call from the command line.
So, it appears we have 2 work-arounds:
library(methods)
back rev your version of Matrix to 1.2-7.1.
Neither is super satisfactory ... I'd just like to know what's going on with Matrix 1.2-8. Maybe it'll be bug-fixed in the next version.
If you're interested, here is my sessionInfo():
R version 3.3.3 (2017-03-06)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.2 LTS
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets base
other attached packages:
[1] glmnet_2.0-5 foreach_1.4.3 Matrix_1.2-8
loaded via a namespace (and not attached):
[1] codetools_0.2-15 grid_3.3.3 iterators_1.0.8 methods_3.3.3
[5] lattice_0.20-35
Oh dear.
I'm pretty (not 100% !) sure that this problem should not apply in newer version of R and Matrix.
Still I would claim this is not a Matrix bug in a proper sense, rather either an 'Rscript' vs 'R' bug -- as #Stu Field mentions already; Rscript does not by default attach the methods package to the search() path, but regular R does.
OTOH, R CMD check Matrix nowadays should try to run Matrix without the methods package being in the search path, and hence the problem should not be present from Matrix 1.2-9 and newer, i.e., by default from R 3.4.0 and newer or then update the 'Matrix' package if you have an older version of R.
Again: Can you please confirm that the problem is gone with R 3.4.0 (which has Matrix 1.2-9 "along with it") ?
Here is a more useful example script, I called Rscript-tst.R.
Run as
Rscript --vanilla Rscript-tst.R > Rscript-tst.Rout 2>&1
or (as myself with many R versions installed) something like
`R-3.4.0 RHOME`/bin/Rscript --vanilla Rscript-tst.R > Rscript-tst.Rout_R340 2>&1
Rscript-tst.R :
options(echo = TRUE)# << even with "Rscript" or --slave ...
(m <- system.file("external/pores_1.mtx", package = "Matrix"))
packageDescription("Matrix")
## This *load*s the Matrix package but does not attach it to search()
str(Matrix::readMM)
sessionInfo()
x <- Matrix::readMM(m)
## used to fail because 'methods' was not "there" (in Rscript only)

Troubleshooting R script called from Rscript.exe

I have an R script that runs fine in RStudio. I am trying to schedule it to run regularly in Windows Task Scheduler with RScript.exe. It failed.
Then I tried running it from command line and noticed an error below.
D:\development\projects\SSCDAPOC\trunk\src\scripts>"C:\Program Files\R\R-3.2.2\bin\x64\Rscript.exe" batch_read_rss_selected.R
Loading required package: xml2
Error in as.vector(x, "list") :
cannot coerce type 'environment' to vector of type 'list'
Calls: do.call ... <Anonymous> -> lapply -> as.list -> as.list.default
Execution halted
When I sourced directly in RStudio for the same script, it worked perfectly fine.
Any tips on how I can investigate and troubleshoot this?
R session info below in case of use:
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_Singapore.1252 LC_CTYPE=English_Singapore.1252
[3] LC_MONETARY=English_Singapore.1252 LC_NUMERIC=C
[5] LC_TIME=English_Singapore.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rvest_0.3.1 xml2_0.1.2
loaded via a namespace (and not attached):
[1] httr_1.0.0 selectr_0.2-3 R6_2.1.1 magrittr_1.5 tools_3.2.2 curl_0.9.4
[7] Rcpp_0.12.2 stringi_1.0-1 stringr_1.0.0 XML_3.98-1.3
After some further searching I found two ways to make this work:
Instead of using Rscript.exe, I force the input into R.exe. i.e. instead of
Rscript.exe batch_read_rss_selected.R earlier, I usedR.exe -f batch_read_rss_selected.R. This worked, and dumped every single line of code in the script on screen also.
Change the script to explicitly include library(methods) . It seems this is not needed for the script to function when running from within R (RStudio IDE in my case), but is needed for Rscript.exe for my script. Now it executes similarly both on command line and from R environment.
I used cmd to call Rscript.exe in Task Scheduler, then gave it an absolute path to my R script, which further defined the output to an rmarkdown file. I should note that I also had to install pandoc on my computer to get it to work (https://pandoc.org/installing.html). But I now have a rmarkdown report which runs every day, and draws data directly from an MSAccess database to provide me with a summary I can send my boss and staff.
Code:
program/script = cmd
additional argument =
/c C:/<yourpath>/Rscript.exe "C:/<yourpath>/run_report.R"
in run_report.R I specify the output:
rmarkdown::render("C:/<yourpath>/filename.Rmd", output_format= NULL,output_file="C:/yourpath>/filename.pdf", knit_root_dir=NULL, runtime="auto", clean=TRUE, run_pandoc = TRUE, quiet=TRUE)

R crashes when trying to output/create plot

All of a sudden my system does no want to create plots from inside an R environment.
When I do just something simple like:
>$R
>X11()
(I can use whatever plotting function of R I want to. Not only X11())
A new windows pops open just like expected but then freezes. It not only freezes the window itself it also freezes the underlying R session. The only way to get out is to xkill the plot window.
After doing that inside R this message pops up:
Error in X11() : X11 fatal IO error: please save work and shut down R
I have Googled through several things but I am not able to solve this. I am working on a CentOS6.7 OS.
sessionInfo()
>R version 3.2.2 (2015-08-14)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS release 6.7 (Final)
>locale:
> [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C
> [3] LC_TIME=en_US.utf8 LC_COLLATE=en_US.utf8
> [5] LC_MONETARY=en_US.utf8 LC_MESSAGES=en_US.utf8
> [7] LC_PAPER=en_US.utf8 LC_NAME=C
> [9] LC_ADDRESS=C LC_TELEPHONE=C
>[11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C
>attached base packages:
>[1] stats graphics grDevices utils datasets methods base `
Try the following:
Include a line to use ggsave to save the plot to a specific file location
Save your script from RStudio and quit/kill your session
Open a terminal, navigate to the folder with your script, and run it with:
Rscript your_code.R
View the plot in the file location you specified in step 1 above

Resources