I am using Jupyter with the Julia Pro Kernel. And I want to just pass from a Julia Script to a Notebook. (I am getting to jupyter via anaconda)
I use the command
using LaTeXStrings to charge that package in the jl file. I use that command in order to put \alpha in the code and automatically appears the greek symbol α.
But when I am doing the same in Jupyter I just can't get the α.
I get this error as an output from that code chunk.
syntax: "\" is not a unary operator
Stacktrace:
[1] top-level scope at In[18]:1
[2] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091
[3] execute_code(::String, ::String) at C:\Users\jparedesm\.julia\packages\IJulia\rWZ9e\src\execute_request.jl:27
[4] execute_request(::ZMQ.Socket, ::IJulia.Msg) at C:\Users\jparedesm\.julia\packages\IJulia\rWZ9e\src\execute_request.jl:86
[5] #invokelatest#1 at .\essentials.jl:710 [inlined]
[6] invokelatest at .\essentials.jl:709 [inlined]
[7] eventloop(::ZMQ.Socket) at C:\Users\jparedesm\.julia\packages\IJulia\rWZ9e\src\eventloop.jl:8
[8] (::IJulia.var"#15#18")() at .\task.jl:356
Does anyone know how can I get the greek alphabet in Jupyter? It'll be very helpful!
If I understand you correctly, you just want to use the greek symbol alpha α. For that you don't need the package LaTeXString. You can just type \alpha and hit the TAB key. Then \alpha should automagically change to α.
LaTeXStrings is used to type LaTeX equations in string literals, like in L"1 + \alpha^2"
Related
My code:
setwd("C:/A549_ALI/4_tert-Butanol (22)/")
list.celfiles()
my.affy=ReadAffy()
dim(exprs(my.affy))
Output:
Show in New Window
[1] "(46) 22-B1-1_(miRNA-4_0).CEL"
[2] "(47) 22-B1-2_(miRNA-4_0).CEL"
[3] "(48) 22-B1-3_(miRNA-4_0).CEL"
[4] "(49) 22-R1-1_(miRNA-4_0).CEL"
[5] "(50) 22-NEC 1-1_(miRNA-4_0).CEL"
[6] "(51) 22-B2-1_(miRNA-4_0).CEL"
[7] "(52) 22-B2-2_(miRNA-4_0).CEL"
[8] "(53) 22-B2-3_(miRNA-4_0).CEL"
[9] "(54) 22-R2-1_(miRNA-4_0).CEL"
[10] "(55) 22-NEC 2-1_(miRNA-4_0).CEL"
[11] "(56) 22-B3-1_(miRNA-4_0).CEL"
[12] "(57) 22-B3-2_(miRNA-4_0).CEL"
[13] "(58) 22-B3-3_(miRNA-4_0).CEL"
[14] "(59) 22-R3-1_(miRNA-4_0).CEL"
[15] "(60) 22-NEC 3-1_(miRNA-4_0).CEL"
[1] 292681 15
Up to here everything works but than I get this error message:
background correction: mas
PM/MM correction : mas
expression values: mas
background correcting...'getOption("repos")' replaces Bioconductor standard repositories, see '?repositories' for details
replacement repositories:
CRAN: https://cran.rstudio.com/
Error in getCdfInfo(object) :
Could not obtain CDF environment, problems encountered:
Specified environment does not contain miRNA-4_0
Library - package mirna40cdf not installed
Bioconductor - mirna40cdf not available
I have already tried to install this package, but I can't find it on the Bioconductor website.
Now I do not know how to proceed. Is there any other way to use the mas5calls function?
I use R 4.2.2.
Thanks for all answers.
This simply means that the package with the cdf-env built upon the chip description (CDF) - file for this type of MicroArray data is not distributed through Bio-conductor. It seems that Affymetrix is not providing those anymore, but you can find them on GEO. (click on the platform and than under "Supplementary file" . Alternatively ask the person you got the data from if they can provide you with the relevant CDFs. Use cfdName() to check which ones you need.
Once you obtained the CDF you can build the R package ( mirna40cdf in your case) that affy needs using the makecdfenv package you can install from Bioconductor. You could also try to use another package called oligo and see if it supports your data.
When running read_xlsx() in my normal .R script, I'm able to read in the data. But when running the .R script with source() in R Markdown, it suddenly takes a long time (> 20+++ mins I always terminate before the end) and I keep getting these warning messages where it is evaluating every single column and expecting it to be a logical:
Warning: Expecting logical in DE5073 / R5073C109: got 'HOSPITAL/CLINIC'
Warning: Expecting logical in DG5073 / R5073C111: got 'YES'
Warning: Expecting logical in CQ5074 / R5074C95: got '0'
Warning: Expecting logical in CR5074 / R5074C96: got 'MARKET/GROCERY STORE'
Warning: Expecting logical in CT5074 / R5074C98: got 'NO'
Warning: Expecting logical in CU5074 / R5074C99: got 'YES'
Warning: Expecting logical in CV5074 / R5074C100: got 'Less than one week'
Warning: Expecting logical in CW5074 / R5074C101: got 'NEXT'
Warning: Expecting logical in CX5074 / R5074C102: got '0'
.. etc
I can't share the data here, but it is just a normal xlsx file (30k obs, 110 vars). The data has responses in all capitals like YES and NO. The raw data has filters applied, some additional sheets, and some mild formatting in Excel (no borders, white fill) but I don't think these are affecting it.
An example of my workflow setup is like this:
Dataprep.R:
setwd()
pacman::p_load() # all my packages
df <- read_xlsx("./data/Data.xlsx") %>% type_convert()
## blabla more cleaning stuff
Report.Rmd:
setwd()
pacman::p_load() # all my packages again
source("Dataprep.R")
When I run Dataprep.R, everything works in < 1 min. But when I try to source("Dataprep.R") from Report.Rmd, then it starts being slow at read_xlsx() and giving me those warnings.
I've tried also taking df <- read_xlsx() from Dataprep.R and moving it to Report.Rmd, and it is still as slow as running source(). I've also removed type_convert() and tried other things like removing the extra sheets in the Excel. source() was also in the setup chunk in Report.Rmd, but I took it out and still the same thing.
So I think it is something to do with R Markdown and readxl/read_xlsx(). The exact same code and data is evaluating so differently in R vs Rmd and it's very puzzling.
Would appreciate any insight on this. Is there a fix? Or is this something I will just have to live with (i.e. convert to csv)?
> sessionInfo()
R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.utf8 LC_CTYPE=English_United Kingdom.utf8 LC_MONETARY=English_United Kingdom.utf8
[4] LC_NUMERIC=C LC_TIME=English_United Kingdom.utf8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] digest_0.6.29 R6_2.5.1 lifecycle_1.0.1 pacman_0.5.1 evaluate_0.15 scales_1.2.0 rlang_1.0.2 cli_3.3.0 rstudioapi_0.13
[10] rmarkdown_2.14 tools_4.2.0 munsell_0.5.0 xfun_0.30 yaml_2.3.5 fastmap_1.1.0 compiler_4.2.0 colorspace_2.0-3 htmltools_0.5.2
[19] knitr_1.39
UPDATE:
So in Markdown, I can use the more generic read_excel() and that works in my setup chunk. But I still get the same Warning messages if I try to source() it, even if the R script sourced is also using read_excel() instead of read_xlsx(). Very puzzling all around.
When you run that code on a .R (and probably other kinds of codes that generate warnings), you will get a summary of warnings. Something like "There were 50 or more warnings (use warning() to see the first 50)".
While if you run that same code on a standard Rmarkdown code chunk, you will actually get the whole 50+ warnings. That could mean you are printing thousands, millions, or more warnings.
If your question is WHY does that happen on Rmarkdown and not on R, I'm not sure.
But if your question is how to solve it, it's simple. Just make sure to add the options message=FALSE and warning=FALSE to your code chunk.
It should look something like this:
{r chunk_name, message=FALSE, warning=FALSE}
setwd()
pacman::p_load() # all my packages again
source("Dataprep.R")
Now, about the "setwd()", I would advise against using anything that changes the state of your system (avoid "side effect" functions). They can create problems if you are not very careful. But that is another topic for another day.
Edit: countmap() is in StatsBase.jl and is working as expected. I'm not sure how to change this to an answered problem or if I should I delete it.
using DataFrames
using CSV
train = DataFrame(CSV.File("training.csv"))
countmap(train.column)
UndefVarError: countmap not defined
Stacktrace:
[1] top-level scope
# In[40]:1
[2] eval
# .\boot.jl:360 [inlined]
[3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
# Base .\loading.jl:1094
I get that error running the code. Was countmap deprecated at some point and I just cannot find any updates about it or am I missing something?
Are you looking for countmap from the StatsBase.jl package?
You can use the following pattern to get a DataFrame instead of a Dict as a result:
combine(groupby(train, :column), nrow)
(in many cases it will be much faster than countmap)
Also instead of:
DataFrame(CSV.File("training.csv"))
it is more efficient to write:
CSV.read("training.csv", DataFrame)
After I installed RStudio, I ran:
library()
Warning message:
libraries '/usr/local/lib/R/site-library', 'usr/lib/R/site-library' contain no packages
Then I input:
.libPaths()
[1] "/home/avalon/R/x86_64-pc-linux-gun-library/3.2"
[2] "/usr/local/lib/R/site-library"
[3] "/usr/lib/R/site-library"
[4] "/usr/lib/R/library"
How can I remove [2] and [3] to prevent the warning message appear again?
Expected output:
.libPaths()
[1] "/home/avalon/R/x86_64-pc-linux-gun-library/3.2"
[4] "/usr/lib/R/library"
Linux
First thing to do is read the manpage on it (?.libPaths), and you'll see:
'.libPaths' is used for getting or setting the library trees that R knows about (and hence uses when looking for packages). If called with argument ‘new’, the library search path is set to the existing directories in unique(c(new, .Library.site, .Library)) and this is returned. If given no argument, a character vector with the currently active library trees is returned.
(emphasis added). This should clue us in to wonder what .Library.site holds. Oddly enough, it holds system-wide (ergo "site") library paths that "should" always be kept, so they are always maintained.
It further goes on to say:
'.Library.site' can be set via the environment variable 'R_LIBS_SITE' (as a non-empty semicolon-separated list of library trees).
So one way to fix it is to give it an empty string when you start R (cannot be done from within R):
# in bash on the command line:
$ R_LIBS_SITE=" " R
# in R
R> .libPaths()
[1] "/usr/lib/R/library"
The way to get this to work with RStudio is by creating a ~/.Renviron file with at least the following:
R_LIBS_SITE=" "
That done, you should not have to do anything further to remove the secondary site library paths from .libPaths():
R> .libPaths()
[1] "/usr/lib/R/library"
Windows
Assuming you're doing the following:
R> .libPaths(c("/home/avalon/R/x86_64-pc-linux-gun-library/3.2", .libPaths()))
[1] "/home/avalon/R/x86_64-pc-linux-gun-library/3.2"
[2] "/usr/local/lib/R/site-library"
[3] "/usr/lib/R/site-library"
[4] "/usr/lib/R/library"
If you want to correct it after you've done this, then just do:
R> .libPaths( c(.libPaths()[c(1,4)]) )
[1] "/home/avalon/R/x86_64-pc-linux-gun-library/3.2"
[2] "/usr/lib/R/library"
Alternatively, you can do it this way the first time (i.e., while it still has three elements, two of which are not good for you):
R> .libPaths(c("/home/avalon/R/x86_64-pc-linux-gun-library/3.2", .libPaths()[3]))
[1] "/home/avalon/R/x86_64-pc-linux-gun-library/3.2"
[2] "/usr/lib/R/library"
There is certainly a way to filter the paths programmatically instead of blindly taking the 3rd element, but this should work for now.
I'm learning mongolite/mongoDB right now, and came across this:
https://cran.r-project.org/web/packages/mongolite/vignettes/intro.html
Inside I saw code like this:
tbl <- m$mapreduce(
map = "function(){emit({cut:this.cut, color:this.color}, 1)}",
reduce = "function(id, counts){return Array.sum(counts)}"
)
Can someone tell me what these functions are written in? I don't think they are R functions.
The R language allows you to create environments where you put functions that are then referenced with the $-operator as one would pull items from a list. So the m$mapreduce is calling an R function and sending that text to the database engine: http://docs.mongodb.org/manual/reference/command/mapReduce/
If you install the package and execute help(pac=mongolite) you will see that the package has a single exposed function, mongo that allows any of those function calls. You can then work through the examples on the help page and the vignette.
(Note: you will get an error if you do not first install and set up the database executable.)
If you execute this with mongolite loaded you get a list of objects in the environment defined when the mongo function was created:
ls(envir=environment(mongo))
There are a set of objects in that environment that appear to hold what you might be interested in:
[14] "mongo_collection_aggregate"
[15] "mongo_collection_command"
[16] "mongo_collection_command_simple"
[17] "mongo_collection_count"
[18] "mongo_collection_create_index"
[19] "mongo_collection_distinct"
[20] "mongo_collection_drop"
[21] "mongo_collection_drop_index"
[22] "mongo_collection_find"
[23] "mongo_collection_find_indexes"
[24] "mongo_collection_insert_bson"
[25] "mongo_collection_insert_page"
[26] "mongo_collection_mapreduce"
[27] "mongo_collection_name"
[28] "mongo_collection_new"
[29] "mongo_collection_remove"
[30] "mongo_collection_rename"
[31] "mongo_collection_stats"
[32] "mongo_collection_update"
The mapreduce functions in the mongolite package are written in javascript. Please see the package docs on CRAN for confirmation (page 3) (a link to external PDF):
mapreduce(map, reduce, query = ’{}’, sort = ’{}’, limit = 0, out = NULL, scope = NULL)
"Performs a map reduce query. The map and reduce arguments are strings containing a JavaScript function. Set out to a string to store results in a collection instead of returning."