How to get a command to run automatically in RStudio Terminal - terminal

I'm on Windows 10.
I want to send a command to a Terminal in RStudio using the rstudioapi. For example:
termId <- rstudioapi::terminalCreate()
rstudioapi::terminalSend(termId, 'dir\n')
My issue is that although the command is sent to the terminal, it does not run automatically. The cursor stays at the end of the line and I need to manually go to the terminal and press Enter.
I have seen many other terminal questions which have the \n at the end of the commands, so I'm certain it should work.
What am I doing wrong?
Thanks!
> sessionInfo()
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)
Matrix products: default
locale:
[1] LC_COLLATE=Spanish_Argentina.utf8 LC_CTYPE=Spanish_Argentina.utf8 LC_MONETARY=Spanish_Argentina.utf8
[4] LC_NUMERIC=C LC_TIME=Spanish_Argentina.utf8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rstudioapi_0.13 RPostgres_1.4.4 DBI_1.1.3
loaded via a namespace (and not attached):
[1] bit_4.0.4 compiler_4.2.1 ellipsis_0.3.2 cli_3.3.0 hms_1.1.1 tools_4.2.1 Rcpp_1.0.8.3
[8] bit64_4.0.5 vctrs_0.4.1 blob_1.2.3 lifecycle_1.0.1 pkgconfig_2.0.3 rlang_1.0.3

In case somebody has the same issue:
I simply replaced the \n with \r and it worked. Don't really understand it as in another laptop it works fine with \n.

Related

Problems using R after update in loadNamespace

I am very new to R. Working mostly with Seurat package to evaluate my single-cell RNAseq data.
Today I wanted to update the R version and RStudio. After that I had problems using installed packages. This is my problem:
> install.packages("Seurat", dependencies = TRUE)
Installing package into ‘C:/Users/benne/AppData/Local/R/win-library/4.2’
(as ‘lib’ is unspecified)
Warning in install.packages :
dependencies ‘S4Vectors’, ‘SummarizedExperiment’, ‘SingleCellExperiment’, ‘MAST’, ‘DESeq2’, ‘BiocGenerics’, ‘GenomicRanges’, ‘GenomeInfoDb’, ‘IRanges’, ‘rtracklayer’, ‘monocle’, ‘Biobase’, ‘limma’ are not available
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.2/Seurat_4.2.0.zip'
Content type 'application/zip' length 2376157 bytes (2.3 MB)
downloaded 2.3 MB
package ‘Seurat’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\benne\AppData\Local\Temp\RtmpIlveV0\downloaded_packages
> library(Seurat)
Error: package or namespace load failed for ‘Seurat’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
there is no package called ‘spatstat.data’
I think, there is no problem with the installation of Seurat-package but I cannot make the library-function work. I found other topics that tried to solve that problem but they did not help me.
What could be the problem? With the old R/RStudio version everything worked well. After the update I had to install the RTools42 because it said I have to do that. I have never done that before, why today??
I really hope, you guys may help me. I am totally lost!!
Attached my sessionInfo():
> sessionInfo()
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)
Matrix products: default
locale:
[1] LC_COLLATE=German_Germany.utf8 LC_CTYPE=German_Germany.utf8 LC_MONETARY=German_Germany.utf8
[4] LC_NUMERIC=C LC_TIME=German_Germany.utf8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] httr_1.4.4 tidyr_1.2.1 viridisLite_0.4.1 jsonlite_1.8.2 splines_4.2.1
[6] leiden_0.4.3 shiny_1.7.2 sp_1.5-0 ggrepel_0.9.1 globals_0.16.1
[11] pillar_1.8.1 lattice_0.20-45 glue_1.6.2 reticulate_1.26 digest_0.6.29
[16] RColorBrewer_1.1-3 promises_1.2.0.1 colorspace_2.0-3 plyr_1.8.7 cowplot_1.1.1
[21] htmltools_0.5.3 httpuv_1.6.6 Matrix_1.5-1 pkgconfig_2.0.3 listenv_0.8.0
[26] purrr_0.3.5 xtable_1.8-4 patchwork_1.1.2 scales_1.2.1 RANN_2.6.1
[31] later_1.3.0 Rtsne_0.16 spatstat.utils_2.3-1 tibble_3.1.8 generics_0.1.3
[36] ggplot2_3.3.6 ellipsis_0.3.2 ROCR_1.0-11 pbapply_1.5-0 SeuratObject_4.1.2
[41] lazyeval_0.2.2 cli_3.4.1 survival_3.3-1 magrittr_2.0.3 mime_0.12
[46] future_1.28.0 fansi_1.0.3 parallelly_1.32.1 MASS_7.3-57 ica_1.0-3
[51] progressr_0.11.0 tools_4.2.1 fitdistrplus_1.1-8 data.table_1.14.2 lifecycle_1.0.3
[56] matrixStats_0.62.0 stringr_1.4.1 plotly_4.10.0 munsell_0.5.0 cluster_2.1.3
[61] irlba_2.3.5.1 compiler_4.2.1 rlang_1.0.6 scattermore_0.8 grid_4.2.1
[66] ggridges_0.5.4 RcppAnnoy_0.0.19 htmlwidgets_1.5.4 igraph_1.3.5 miniUI_0.1.1.1
[71] gtable_0.3.1 codetools_0.2-18 reshape2_1.4.4 R6_2.5.1 gridExtra_2.3
[76] zoo_1.8-11 dplyr_1.0.10 fastmap_1.1.0 future.apply_1.9.1 rgeos_0.5-9
[81] utf8_1.2.2 KernSmooth_2.23-20 stringi_1.7.8 parallel_4.2.1 Rcpp_1.0.9
[86] sctransform_0.3.5 vctrs_0.4.2 png_0.1-7 tidyselect_1.2.0 lmtest_0.9-40
Thank you so much!
I tried to find out what the problem could be. I had hope that the installation of RTools42 may work but that does not make it better. The error still occurs.
Issue occurred for me as well after upgrading to R-4.2.1. Following steps helped me resolve the issue:
Restart the computer after successful installation of R Tools
Run following commands
install.packages('spatstat.data')
install.packages('spatstat.core')
After RTools wraps up it's compilation as mentioned in answer by Maso Sato
Library(Seurat) should load fine!
I had a similar problem with my installation of R, RStudio, and Seurat today (2022/10/26).
(I did not have a problem on another computer a few weeks ago).
install.packages('Seurat') said that I should install RTools.
I did so, and I got a similar error messages as yours when executing library(Seurat).
Then, I executed install.packages('spatstat.data').
RTools had to recompile various things (gcc), but at the end, library(Seurat) ran smoothly.

Problem in generating a GNU screen session with ruby in Ubuntu 20.04

I have a workstation with Ubuntu 20.04 installed where I'm facing problem in generating GNU screen session inside a ruby script.
The ruby script has to generate a new GNU screen session with a custom name and attach the new session to a VNC server process.
Here is the code:
when 'screen'
sd=options[:screen_dir]
if sd then
FileUtils.mkdir_p(sd)
FileUtils.chmod 0700, sd
ENV['SCREENDIR']=sd
end
if !options.has_key?(:screen_exe) then
raise Error.new(:ExecuteRun, :option=>"screen_exe",:screen_dir=>sd, :mode => mode)
end
if !options.has_key?(:screen_conf) then
raise Error.new(:ExecuteRun, :option=>"screen_conf", :screen_dir=>sd, :mode => mode)
end
command="#{options[:screen_exe]} -L -c #{options[:screen_conf]} "+
" -dmS sessionname #{command}"
output=%x{#{command}}
status=$?.exitstatus
so1=%x{#{options[:screen_exe]} -ls}.
split.
find { |x| x =~ /^[0-9]+\.sessionname$/ }
if so1.kind_of?(Array) then
so=so1.map { |x| x.gsub(/^([0-9]+)\.sessionname$/,'\\1') }
else
so=[ so1.gsub(/^([0-9]+)\.sessionname$/,'\\1') ]
end
{ :output => output, :status => status, :pid => so[-1]}
After creating a folder where copying the screen_rc configuration and storing the GNU screen log, a new screen session is generated with logging (-L), a custom name (-S), detached mode (-d), skipping STY env variable (-m).
I introduced some debug messages (for example, screen ls command), which show me no generated sessions after the command is issued.
This behaviour is quite strange because the same ruby script works perfectly in the previous Ubuntu version (16.04 and 18.04). I noticed that the GNU screen version differs between these distributions: Ubuntu 16.04: 4.03.01 Ubuntu 18.04: 4.06.02 Ubuntu 20.04: 4.08.00
Also immediately after rebooting the workstation, the script works...but just for the first run...it seems that something remains pending, but there are no pending processes...
I found a temporary workaround downgrading the screen version to the 4.03.01 (Ubuntu 16.04), making the script working also in Ubuntu 20.04...but I would like to solve the problem with the newer version of GNU screen for the full porting of the script on the latest version of Ubuntu.
Thank you for the help in advance!

R markdown pandoc document conversion failed with error 1 after updating pandoc from 1.19 to 2.4

I recently installed pandoc 2.4 on Windows and the conversion failed with error 1 occurs for all knitting. I can't knit html, word, and pdf.
The error says
output file: template.knitmd
pandoc.exe: template.utf8.md: openBinaryFile: does not exist (No such file or directory)
Error: pandoc document conversion failed with error 1
Execusion halted
This happens to even the raw basic template rmd file.
I am using a closed network without internet connection and limited writing permission. Previously I was able to knit rmd files located in documents folder generating outputs in same location.
The sessionInfo() says
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: windows >=8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_collate=english_united states.1252 lc_ctype=english_united states.1252 lc_monetary=english_united states.1252
[4] LC_Numeric=C LC_TIME=english_united states.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] flextable_0.4.5 officer_0.3.2 knitr_1.20 rmarkdown_1.10
loaded via a namespace (and not attached):
[1] Rcpp_1.0.0 digest_0.6.18 rprojroot_1.3-2 R6_2.3.0 backports_1.1.2 magrittr_1.5 evaluate_0.12
[8]zip_1.0.0 stringi_1.2.4 gdtools_0.1.7 uuid_0.1-2 xml2_1.2.0 tools_3.5.1 stringr_1.3.1
[15] yaml_2.2.0 compiler_3.5.1 base64enc_0.1-3 htmltools_0.3.6
Any advice will be highly appreciated. (Or even ways how to change the settings back to old pandoc version without deleting the version 2.4.)
I have had this issue as well. Mapping the network drive where my R project was stored by following the instructions here solved the issue for me.

How to change lib-path for an RStudio project?

I set R_LIBS_USER to my desired library path in my system environment variables (I already moved my old library to that location). RStudio respects that path when I start the program without opening an existing file. But when I open RStudio by clicking on an .Rproj file, it loads an old lib path and ignores R_LIBS_USER (.libPaths() returns the old path). I searched my %UserProfile% directory and project directory for mentions of the old string. I can't find anything in %UserProfile% directory except in the history_database file, and likewise in the project directory, except for one mention in .Rproj-user\B37F6204\pcs\packages-pane.pper:
{
"installOptions" : {
"installDependencies" : true,
"installFromRepository" : true,
"libraryPath" : "<my-userprofile-path>/R/win-library/3.3"
}
}
This looked promising, but when I changed it, RStudio still ignores it when I open the project.
Clicking on .Rproj files is pretty convenient so I'd like to fix this.
RStudio version is 1.0.136
> sessionInfo()
R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] tools_3.3.3

RStudio viewer in external browser Issues in Ubuntu14.04

I have one Ubuntu14.04 laptops,
when I run below with RStudio Viewer, it work fines.
> library(dygraphs)
> dygraph(ldeaths, main = "All", group = "lung-deaths")
After I set below options to run in external browser,
options("viewer"=NULL)
dygraph(ldeaths, main = "All", group = "lung-deaths")
The browser will open files with below URL but nothing show:
http://localhost:18186/session/viewhtmla4c45554fcb/index.html
If I do the same thing in R console
library(dygraphs)
dygraph(ldeaths, main = "All", group = "lung-deaths")
it work fine and will open with URL with file:///tmp/RtmpE7nROm/viewhtmlf371b65fc2c/index.html
Questions1: Why Rstudio will open "http://localhost:18186..." instead of "file://....."?
Questions2: What commands in Rstudio to revert the display show in Viewer again? Currently I have to quit Rstudio and restart to get show in Viewer again.
PS: I doesn't see this issue in another Linux Labtops, not sure what configuration will causing this, hope someone can help to answer!
Below are sessionInfo() show in RStudio
sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.3 LTS
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=zh_TW.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=zh_TW.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=zh_TW.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=zh_TW.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dygraphs_0.4.6
loaded via a namespace (and not attached):
[1] htmlwidgets_0.5 zoo_1.7-12 magrittr_1.5 htmltools_0.2.6 tools_3.2.2 xts_0.9-7
[7] rstudioapi_0.3.1 yaml_2.1.13 grid_3.2.2 jsonlite_0.9.16 digest_0.6.8 lattice_0.20-33

Resources