Why I cannot get this string in RStudio? - r

I am trying to read a phylogeny (as text) into R using RStudio. I copied the text and put them in quotes. But now I cannot even assign it to a variable in R.
tree = "(((((((((((((Potentilla_intermedia:0.311566,Potentilla_recta:0.311566):0.802855,Potentilla_pensylvanica:1.114421):0.041676,(Potentilla_gracilis:1.110417,Potentilla_argentea:1.110417):0.04568):8.56704,(((Potentilla_norvegica:0.063773,Potentilla_supina:0.063773):0.051902,Potentilla_hippiana:0.115675):8.590754,Argentina_anserina:8.706429):1.016709):0.602701,Potentilla_bipinnatifida:10.325839):8.923901,(((Potentilla_anglica:1.366781,Potentilla_reptans:1.366781):5.302408,(Potentilla_simplex:0.031597,Potentilla_canadensis:0.031597):6.637592):0.621378,Duchesnea_indica:7.290567):11.959172):1.543066,Potentilla_sterilis:20.792806):11.333216,(((((Fragaria_chiloensis:2.648747,Fragaria_vesca:2.648747):1.022985,Fragaria_virginiana:3.671731):17.684618,(Dasiphora_fruticosa:11.647099,Potentilla_arguta:11.647099):9.709251):0.676268,Drymocallis_arguta:22.032617):0.405466,((Alchemilla_monticola:16.875311,Alchemilla_xanthochlora:16.875311):0.887368,Comarum_palustre:17.762679):4.675404):9.687939):6.026567,((((((((Rosa_setigera:3.378155,Rosa_blanda:3.378155):0.030747,Rosa_carolina:3.408902):0.025377,Rosa_arkansana:3.434279):1.991106,((Rosa_rubiginosa:2.358272,Rosa_spinosissima:2.358272):0.07664,Rosa_multiflora:2.434911):2.990474):0.128884,Rosa_woodsii:5.554269):0.86504,Rosa_acicularis:6.419309):6.730804,(((((Rosa_micrantha:0.188519,Rosa_canina:0.188519):0.012649,Rosa_tomentosa:0.201168):0.03073,Rubus_plicatifolius:0.231898):0.29401,Rosa_palustris:0.525908):2.38304,Rosa_rugosa:2.908948):10.241165):23.677485,((((Agrimonia_pubescens:0.020923,Agrimonia_gryposepala:0.020923):3.336778,Agrimonia_striata:3.357701):1.373162,(Agrimonia_rostellata:1.363567,Agrimonia_parviflora:1.363567):3.367296):20.869366,Sanguisorba_minor:25.600229):11.227369):1.324992):6.47604,((((Geum_laciniatum:1.819705,Geum_canadense:1.819705):3.890036,(Geum_aleppicum:5.612049,Geum_urbanum:5.612049):0.097692):2.792243,((Geum_macrophyllum:2.602326,Geum_triflorum:2.602326):2.49947,Geum_vernum:5.101796):3.400188):2.651319,Geum_rivale:11.153303):33.475326):1.449852,((((((((((((((((((((((Rubus_semisetosus:2.411266,Rubus_frondosus:2.411266):0.563329,Rubus_wisconsinensis:2.974595):0.095095,(Rubus_wheeleri:2.378801,Rubus_fulleri:2.378801):0.690888):0.0356,Rubus_glandicaulis:3.10529):0.272207,(Rubus_miscix:2.288585,Rubus_spectatus:2.288585):1.088911):0.685377,(Rubus_ithacanus:3.983737,Rubus_steelei:3.983737):0.079136):0.015284,Rubus_enslenii:4.078157):0.068184,Rubus_pensilvanicus:4.146341):0.314926,(Rubus_argutus:0.58418,Rubus_cuneifolius:0.58418):3.877087):0.02081,(((Rubus_regionalis:4.019817,Rubus_canadensis:4.019817):0.059086,Rubus_rosa:4.078903):0.160428,Rubus_recurvans:4.239331):0.242746):0.015005,(Rubus_allegheniensis:4.31499,Rubus_uvidus:4.31499):0.182092):0.019612,Rubus_vermontanus:4.516694):0.891371,(Rubus_hispidus:4.440803,Rubus_permixtus:4.440803):0.967262):1.32483,Rubus_vagus:6.732895):0.023439,Rubus_superioris:6.756333):0.020104,(((((((Rubus_trivialis:1.652243,Rubus_flagellaris:1.652243):0.36229,(Rubus_multifer:0.538518,Rubus_curtipes:0.538518):1.476014):0.807236,Rubus_stipulatus:2.821768):0.295305,Rubus_junceus:3.117074):0.198123,Rubus_missouricus:3.315197):0.971918,Rubus_elegantulus:4.287115):2.388002,Rubus_alumnus:6.675117):0.101321):0.025475,((Rubus_laciniatus:0.125186,Rubus_bifrons:0.125186):0.11903,Rubus_praecox:0.244216):6.557697):4.346196,Rubus_pubescens:11.148109):0.061953,Rubus_idaeus:11.210062):0.042458,((Rubus_phoenicolasius:11.083887,Rubus_occidentalis:11.083887):0.087068,Rubus_arcticus:11.170956):0.081565):7.121242,((Rubus_uniformis:8.388795,Rubus_parviflorus:8.388795):6.470355,Rubus_odoratus:14.85915):3.514612):14.711986,Rubus_meracus:33.085749):12.992732):16.915234,((Filipendula_rubra:19.826137,Filipendula_vulgaris:19.826137):0.073841,Filipendula_ulmaria:19.899978):43.093736):13.354116,(((((((((((((((((((((((((((((((((((Crataegus_dodgei:0.015733,Crataegus_dissona:0.015733):0.010796,Crataegus_michauxii:0.026529):0.010633,Crataegus_formosa:0.037162):0.011471,Crataegus_pedicellata:0.048633):0.014098,Crataegus_irrasa:0.062731):0.019132,Crataegus_florifera:0.081863):0.032863,Crataegus_lumaria:0.114726):0.465517,Crataegus_fulleriana:0.580243):0.006081,Crataegus_disperma:0.586324):0.099168,(Crataegus_jesupii:0.549784,Crataegus_lucorum:0.549784):0.135708):0.00584,Crataegus_fluviatilis:0.691331):0.380201,Crataegus_scabrida:1.071532):0.019968,Crataegus_calpodendron:1.0915):0.033869,Crataegus_succulenta:1.125369):0.262341,((Crataegus_holmesiana:0.712472,Crataegus_mollis:0.712472):0.144634,Crataegus_coccinioides:0.857106):0.530604):0.398534,Crataegus_marshallii:1.786245):0.228259,Crataegus_crus-galli:2.014503):0.161619,Crataegus_intricata:2.176122):0.016118,((Crataegus_macrosperma:0.790887,Crataegus_pruinosa:0.790887):0.122301,(Crataegus_chrysocarpa:0.193226,Crataegus_macracantha:0.193226):0.719962):1.279051):0.017649,Crataegus_submollis:2.209889):0.014998,Crataegus_phaenopyrum:2.224886):0.018512,Crataegus_uniflora:2.243399):0.438351,Crataegus_persimilis:2.68175):0.045017,Crataegus_punctata:2.726768):0.058153,Crataegus_laevigata:2.78492):0.065678,Crataegus_spathulata:2.850598):0.26874,Crataegus_viridis:3.119338):0.332928,Crataegus_douglasii:3.452267):0.094595,Crataegus_monogyna:3.546862):3.832148,((((((Malus_toringo:2.491744,Malus_pumila:2.491744):1.007309,Malus_baccata:3.499053):1.351718,Malus_coronaria:4.850771):1.621923,(Malus_angustifolia:0.049008,Malus_ioensis:0.049008):6.423685):0.035427,Cotoneaster_divaricatus:6.50812):0.736585,Chaenomeles_speciosa:7.244705):0.134305):1.72489,((Aronia_arbutifolia:0.094396,Aronia_melanocarpa:0.094396):8.89729,(Pyrus_communis:7.94625,Sorbus_aucuparia:7.94625):1.045436):0.112214):0.313393,((((Amelanchier_spicata:5.295684,Amelanchier_sanguinea:5.295684):0.053588,Amelanchier_alnifolia:5.349272):2.667629,((Amelanchier_arborea:0.249044,Amelanchier_bartramiana:0.249044):0.767662,Amelanchier_canadensis:1.016706):7.000194):0.24348,(Amelanchier_interior:7.807145,Amelanchier_laevis:7.807145):0.453236):1.156912):0.239145,Sorbus_decora:9.656438):1.019952,Sorbus_americana:10.67639):38.78046,((((((((((((Prunus_hortulana:3.586661,Prunus_persica:3.586661):0.523019,Prunus_mexicana:4.10968):0.275607,Prunus_munsoniana:4.385286):0.329537,(Prunus_armeniaca:1.156849,Prunus_tomentosa:1.156849):3.557974):0.032697,(Prunus_angustifolia:4.478999,Prunus_pumila:4.478999):0.268521):0.03745,Prunus_alleghaniensis:4.784971):1.404974,(Prunus_americana:2.365429,Prunus_nigra:2.365429):3.824516):0.37487,(Prunus_cerasus:2.734566,Prunus_pensylvanica:2.734566):3.830249):4.856241,((Prunus_padus:1.415647,Prunus_virginiana:1.415647):3.401352,Prunus_serotina:4.817):6.604057):29.162527,Sorbaria_sorbifolia:40.583584):2.924475,(Rhodotypos_scandens:36.33611,Physocarpus_opulifolius:36.33611):7.17195):2.718224,(((Spiraea_X_bumalda:10.834237,Spiraea_alba:10.834237):3.799914,Spiraea_tomentosa:14.634152):11.287431,Aruncus_dioicus:25.921583):20.304701):3.230567):26.89098);"
Note: it works on macOS R app, but not on terminal R or RStudio.
Can anyone run the above code? I am surprised that this does not work. There must be something basic about R that I am not know, even after using it for year...
Thanks!
R version 3.5.3 (2019-03-11)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.4
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.5.3 assertthat_0.2.1 cli_1.1.0 tools_3.5.3 withr_2.1.2 rstudioapi_0.9.0
[7] crayon_1.3.4 packrat_0.5.0 sessioninfo_1.1.1

I can't explain why it works differently in different console environments, and particularly why it does work in the MacOS R application (for me it doesn't work under an ESS shell in Ubuntu), but the link given above points to a comment in the Introduction to R:
Command lines entered at the console are limited^4 to about 4095 bytes (not characters)
If you put the code above in a file and source() it, it works fine. nchar(tree) is 6936.
The discussion in the link also points to the place where the limit is hardcoded in R, so if you were really desperate you could modify that value and recompile R ...

Related

Error in inla.call.builtin() : INLA installation error; no such file

I have recently updated INLA using the inla.update on my machine. Now everytime I try to run a function from the package, such as inla.mesh.2d I obtain the following error:
Error in inla.call.builtin() : INLA installation error; no such file
I tried uninstalling and reinstalling INLA package both in its testing and stable version but it still won't work.
I will paste below the output from sessionInfo():
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] it_IT.UTF-8/it_IT.UTF-8/it_IT.UTF-8/C/it_IT.UTF-8/it_IT.UTF-8
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] INLA_22.01.16 sp_1.4-5 foreach_1.5.1 Matrix_1.3-4
loaded via a namespace (and not attached):
[1] compiler_4.0.3 tools_4.0.3 tinytex_0.32 splines_4.0.3 codetools_0.2-18 grid_4.0.3
[7] iterators_1.0.13 xfun_0.23 lattice_0.20-44
Thank You!
The error you are getting may solve if you update your R to its latest version so INLA requirements are met. Restart, and it may resolve.
If this does not resolve the problem, installing directly from the R interface (vs RStudio) might fix the problem. This link explains how it is done and might be helpful if the first solution did not help.
https://groups.google.com/g/r-inla-discussion-group/c/f3LAE2VHZQw

opencv crashing R session?

I'm running some very simple code:
library(opencv)
ocv_video(ocv_face)
And the session immediately aborts.
Any ideas? (note: running R 4.0.2)
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.5
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] opencv_0.1
loaded via a namespace (and not attached):
[1] compiler_4.0.2 magrittr_1.5 tools_4.0.2 Rcpp_1.0.4.6
Solution
For anyone else who arrives here, the solution is to run the same code from terminal. That is press cmd + space to bring up spotlight search, type terminal to open terminal. Type R to open the R interpreter, and use that instead of RStudio.
Cause of the crash
The reason it works from terminal but no RStudio is because from terminal, a prompt will appear asking you to give opencv permission to use your webcam, but this prompt will not appear in RStudio (it causes the crash).

How to get a tagged version of a hugo theme via blogdown

Building a new website using the R package blogdown and the Hugo academic theme worked a few weeks (?) ago:
blogdown::new_site(theme = "gcushen/hugo-academic")
The same command today produces a non-functional webpage, perhaps because of an update to hugo-academic. See discussion:
https://github.com/gcushen/hugo-academic/issues/594
So, I would like to use a previously tagged version of hugo-academic. It seems like things should still work, for example, with version 2.0.1. So, I tried this:
blogdown::new_site(theme = "gcushen/hugo-academic/tree/v2.1.0")
This runs, but I think is produces the same non-functional website as the normal command. That is, I am not actually downloading the v2.1.0 tag of hugo-academic that I want.
Is there a way to do that?
sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] blogdown_0.6
loaded via a namespace (and not attached):
[1] compiler_3.5.0 bookdown_0.7 tools_3.5.0 yaml_2.1.19 knitr_1.20
[6] xfun_0.3
Please read the documentation ?blogdown::new_site for the syntax of the theme argument instead of guessing. The documentation says you should specify the tag name after #, e.g.,
blogdown::new_site(theme = "gcushen/hugo-academic#v2.1.0")
If you have the previous version of the theme that works:
make a copy of all the project (the folder) that worked;
rename the folder;
modify config.toml file in the new project;
modify other contents as required;
create a new website.

Synchronizing R system settings from Terminal, GUI and RStudio

My problem on my MacOS is that I can use R from GUI (aka console, downloaded from CRAN), Terminal or from RStudio but I cannot have them function in the same way.
Specific example is I can use rJava on Terminal and RStudio but not on GUI. Similar stuff happens for Rmarkdown pdf outputs. I usually get errors from GUI but everything is fine on Terminal or RStudio. How do I update R GUI settings to the same as Terminal's?
ps. For instance R CMD javareconf command handled the Terminal R but not R GUI.
edit: It is not actually something that requires a minimal working example but let's try library(rJava) after installing it.
R Called from Terminal (same with RStudio)
No problems.
sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.5
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] C/UTF-8/C/C/C/C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.5.0
R GUI
sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.5
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.5.0 tools_3.5.0
Some differences between Sys.getenv() are GUI has the following extra
LD_LIBRARY_PATH :#JAVA_LD#
DYLD_LIBRARY_PATH /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/lib/server
Brief update: I was able to correct Rmarkdown situation by using this link and reading help by writing ?Startup on R console. Changed the Renviron file on my R.home()/etc/. But still no rJava.
For R Markdown problem, I managed to handle it by adding a ~/.Renviron file and defining PATH parameter with the value I got from Terminal's Sys.getenv() parameters.
The only thing that worked for rJava for High Sierra is the following answer (changed the version to 3.5 though)
https://stackoverflow.com/a/47685001/3608936

Re-initialize with packrat::init()

I have no idea how to make this problem reproducible, but here is a description of the problem nevertheless. I upgraded to R v 3.4.0 yesterday (sessionInfo() is below) and one of my RStudio projects couldn't update packages in packrat. After messing around with various "fixes" without success, I decided to delete packrat (packrat directory, project dir's .RStudio file) in the end. Unfortunately, I can't seem to re-initialize packrat in this project now. The following is the R output from
> packrat::init()
Initializing packrat project in directory:
- "~/my-project-path"
Error in isNamespaceLoaded(pkg) :
attempt to use zero-length variable name
In addition: Warning message:
In FUN(X[[i]], ...) : Package '' not available in repository or locally
> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.4.0 magrittr_1.5 tools_3.4.0 yaml_2.1.14 stringi_1.1.5
[6] knitr_1.15.1 stringr_1.2.0 packrat_0.4.8-1 evaluate_0.10
Any help is very much appreciated. I thought about re-cloning the repo from github, but that would involve copy a large amount of files over from various directories that aren't under revision control currently.
Thanks!

Resources