New user needs help, Julia JuliaPro Juno R RStudio XRJulia in Windows 10

Hi I am having all kinds of problem getting started with Julia. This is like my 4th attempt.

My background is in maths, numerical methods, optimisation, environmental modelling using Matlab, RStudio, Excel, Fortran.

R/RStudio is my current tool of choice, it’s great for data wrangling and plotting, but it’s slow for intensive computation, so I’m exploring XRJulia, which allows Julia code to be run from R.

I installed JuliaPro 0.6.2.1. I am simultaneously trying to figure out XRJulia and Juno/Atom/JuliaPro/whateveritiscalled.

One issue I faced was that installing Julia/JuliaPro does not set the path to point to Julia. So I had to do this manually.

So currently I am trying to do plot in Juno. Either in Winston or Gadfly, neither of them seem to work. It seems I have to load Tk before Winston for some reason, I guess the dependencies aren’t working properly.

What I want to know right now, is how do I execute my script line by line? Ctrl-Enter executes one line but it doesn’t move the cursor to the next line. And I can’t find the setting to change in Atom.

Help!

Next question is how do I get the plot to display in the plot window in Juno?

# Pkg.add("Winston")
# http://winston.readthedocs.io/en/latest/examples.html
using Tk
using Winston
x = linspace(0, 3pi, 100)
c = cos.(x)
s = sin.(x)

p = FramedPlot(
        title="title!",
        xlabel="\\Sigma x^2_i",
        ylabel="\\Theta_i")

add(p, FillBetween(x, c, x, s))
add(p, Curve(x, c, color="red"))
add(p, Curve(x, s, color="blue"))

p

“Moronically” doesn’t sound like the right sort of language mate. Coming from Rstudio I also got used to Ctrl-Enter. But the equivalent in Atom is Shift-enter and Ctrl-enter is designed to stay at the current line. You may note that Jupyter uses that convention as well. As there is nothing stupid, just conventions…

For plotting, I found that “Plots.jl” is a good choice. It lets me use different backend using the same syntax. I use the GR backend alot. I think you install that by doing Pkg.add("GR") and then

using Plots
Plots.gr()

should work.

1 Like

Thank you sir!

By the way, what is a “backend”. I never heard of this before. Does Winston need an additional backend?

Also, when I find a Julia package in Github, where can I find the documentation?

Julia has many plotting packages just like R but in R ggplot2 is dominant. Each plotting package is a “backend”. But you can use Plots.jl so that you can just write plotting code in Plots.jl syntax and not have to worry (so much) about which “backend” is plotting your plots.

1 Like

usually, there is a link to “Stable” doc. If not then the page you land on shows the README file should should have some quick starts.

1 Like

I got this example working in XRJulia.

XRJulia example

Now I want to modify it so the Julia code is in a separate module, but I’m having a very unsuccessful time of it. I made a file called combin.jl (see below). Can’ anyone tell me how to import these two functions into R now? I thought the following was working but seems it’s not.

> library(XRJulia)
> library(HDeconometrics)
> findJulia()
[1] "C:\\Users\\WoodwardS\\AppData\\Local\\JuliaPro-0.6.2.1\\Julia-0.6.2\\bin\\julia.exe"
> juliaAddToPath(getwd(), "combin.jl") # tell Julia to looks for modules here
[1] TRUE
> # find function reg() in combin.jl
> regjl <- juliaEval("reg", "combin.jl")
Error: lexical error: invalid char in json text.
                                       NA
                     (right here) ------^

This is combin.jl:

module combin 

  using Combinatorics

  export reg, csr 

  function reg(x,y)
  
    n=size(x,1)
    xreg=hcat(ones(size(x)[1],1),x)
    k=size(xreg,2)
    p1=((xreg'xreg)^(-1))
    b=p1*xreg'y
    r=y-xreg*b
    sig=(r'r)/(n-k)
    vmat=sig[1]*p1
    sigb=sqrt.(diag(vmat))
    t=b./sigb
    return (b,t)
       
  end
  
  function csr(x,y,k,K,fixed_controls)
  
    fixed_controls=floor(Int,fixed_controls)
    if fixed_controls!=0
    w=x[:,fixed_controls]
    nonw=setdiff(1:size(x,2),fixed_controls)
    end
    if fixed_controls[1]==0
    nonw=1:size(x,2)
    end
    
    save_stat=zeros(size(x,2),2)
    save_stat[:,2]=1:size(x,2)
    for i in nonw
    if fixed_controls[1]==0
    (betas,tstat)=reg(x[:,i],y)
    save_stat[i,1]=abs(tstat[2])
    end
    if fixed_controls!=0
    (betas,tstat)=reg(hcat(w,x[:,i]),y)
    save_stat[i,1]=abs(tstat[end])
    end
    end
    
    t_ord = sortperm(save_stat[:,1],rev=true)
    save_stat=save_stat[t_ord,:]
    
    selected=save_stat[1:K,2]
    
    comb=collect(Combinatorics.combinations(selected,k))
    m=size(comb)[1]
    final_coef=zeros(m,size(x,2))
    final_const=zeros(m)
    
    if fixed_controls!=0
    for i in 1:m
    xr=hcat(x[:,fixed_controls],x[:,floor(Int,comb[i])])
    (model,tstat)=reg(xr,y)
    final_const[i]=model[1]
    model1=model[2:end]
    if length(fixed_controls)>1
    final_coef[i,fixed_controls]=model1[1:(size(fixed_controls)[1])]
    model2=model1[size(fixed_controls)[1]+1:end]
    else
    final_coef[i,fixed_controls]=model1[1]
    model2=model1[2:end]
    end
    
    final_coef[i,floor(Int,comb[i])]=model2
    end
    elseif fixed_controls[1]==0
    for i in 1:m
    (model,tstat)=reg(x[:,floor(Int,comb[i])],y)
    final_const[i]=model[1]
    final_coef[i,floor(Int,comb[i])]=model[2:end]
    end
    end
    aux=hcat(final_const,final_coef)
    result=[mean(aux[:,i]) for i in 1:size(aux)[2]]
    
  end

end