JULIA : LoadError: UndefVarError: add_vertex! not defined - julia

I am trying to create a simple type of Graph before putting more efforts on the bigger one I will have to create with data implementation and I figured out that add_vertex! was exactly what I needed to add a special type of vertex into my graph.
Here is the simple example I tried and I get the reply that add_vertex! is not defined..
module VSRPGraphModule
using Graphs, LightGraphs, MetaGraphs
g = DiGraph()
println(g)
v=ExVertex(1,"ex")
port=VSRPPort()
FillPort(port,"La Havane",10)
v.attributes["port"]=port
println(v.attributes["port"].name)
add_vertex!(g,v)
println(g)
end
And the codes stops at the add_vertex! line returning:
LoadError: UndefVarError: add_vertex! not defined
I did Pkg.update()
I did put the package into julia.
I really don't know why it is not working, is it a problem of the new Julia version 0.6.9 ?
Thanks in advance for your help !

tl;dr Try just using LightGraphs + MetaGraphs (not Graphs).
LightGraphs and Graphs are separate packages and I don't think they work together. IIRC Graphs is no longer maintained so if you can then just use LightGraphs.
Regardless, if you try to use two packages that export the same method (add_vertex!) you'll need to specify which one you want to call.
e.g. Graphs.add_vertex! or LightGraphs.add_vertex!.

Related

Julia doesn't find packages in depot_path anymore

I have a problem with using packages in Julia. It has worked before, and I'm not really sure why this has changed or how to troubleshoot.
I have a folder
/my_path/julia/packages
with Julia packages. For example, there is a folder
/my_path/julia/packages/FFTW/
with the FFTW package.
Further, I have changed the depot path to point at this directory by assigning JULIA_DEPOT_PATH before starting julia, so that
Base.DEPOT_PATH = ["/my_path/julia/"]
However, if I run
julia> using FFTW
I get the following error message:
ERROR: ArgumentError: Package FFTW not found in current path:
- Run `import Pkg; Pkg.add("FFTW")` to install the FFTW package.
Any idea how I can troubleshoot or fix this?
Manipulating Base.DEPOT_PATH does not seem like a good idea.
The code proposed by #cmc will does not work (at least on Julia 1.3.1):
julia> Base.DEPOT_PATH = ["/some/path"]
ERROR: cannot assign variables in other modules
There is a workaround:
Base.DEPOT_PATH[1] = "/some/path"
However, the correct way is to assign the JULIA_DEPOT_PATH system variable before starting Julia, Windows:
set JULIA_DEPOT_PATH=c:\some\path
or
set JULIA_DEPOT_PATH=c:\some\path1;c:\some\path2
Linux/OSX:
export JULIA_DEPOT_PATH=/some/path
or
export JULIA_DEPOT_PATH=/some/path1:/some/path2
Unless you have a specific reason to do so (and if this is the case I'd be interested to hear it!), you don't need to fiddle with the DEPOT_PATH or LOAD_PATH variables: using Julia's package manager should be enough to cover your needs most of the time.
In this specific instance, have you tried to do what the error message suggests?
julia> import Pkg
julia> Pkg.add("FFTW")
LOAD_PATH, not DEPOT_PATH, will modify code loading.
You want to do something like push!(LOAD_PATH, /my_path/julia/packages).
I will echo #ffevotte and strongly suggest to not modify LOAD_PATH unless necessary. The benefits of organizing dependencies into Pkg environments far outweigh the small overhead of declaring them explicitly through Pkg.add.

Is there a reason why plot gives an error in atom but works fine on jupyter-notebook?

I am a new user of Julia. I want to start using Julia in Atom using Juno. Before I did some tutorials using jupyter-notebooks.
Now the when I tried to run the code below it returns the following error message.
When I run the same code, on the same machine in a jupyter-notebook I do not get an error.
There are a lot of people online that get the same error but none of the solutions could help me. It seems to me that the problem that plots is not precompiling correctly.
For example: Plot not defined with Julia
using Plots
x = 1:10;
y = rand(10); # These are the plotting data
plot(x,y)
UndefVarError: plot not defined
top-level scope at testatom.jl:3
This should work, try rebuilding plots?
using Pkg;pkg”build Plots”
Also do any updates suggested in atom.
Also, which version of julia? Please note that link is very old...

How to fix LoadError for loading Escher in julia?

I'm a beginner to julia and I'm having the problem for loading Escher in julia. Every time when I wanted to import the Package Escher it always has the problems saying:
WARNING: could not import Base.writemime into Escher
ERROR: LoadError: LoadError: syntax: ""A Tile is the basic currency in Escher.
Most of the functions in the Escher API take Tiles
among other things as arguments, and return a Tile as the result.
Tiles are immutable: once created there is no way to mutate them.
"" is not a valid function argument name
Does anyone know how to fix it? Thanks. By the way I'm using julia v0.7. I've tried in julia 1.0 before and it also didn't work.

Julia: pcaeig(X) yields "UndefVarError: fliplr not defined"

I am trying to get the eigenvector to do pca (principal component analysis). The package, DimensionalityReduction.jl offers a command that should do that very thing, pcaeig(X) where X is some matrix. My code is as follows
using DataFrames
using DimensionalityReduction
data = readtable("Midterm Data.csv")
T=size(data)[1]
n=size(data)[2]
erates = convert(Array,data[1:T,2:n])
eigvec = pcaeig(erates)
I do apologize that the formatting is bad, I don't quite remember how to put the code in a quote. Anyways, when I try to run this code, I get the following error: "UndefVarError: fliplr not defined". Now, to my knowledge, fliplr is a command used to flip a matrix (not a variable). It is also saying that the error is happening in the code for the package (not my code). Does this mean that I am out of luck and cannot use this package until it gets patched? If so, does anyone else know another method to get the eigenvector for pca?
As it says in the README of DimensionalityReduction, the package is deprecated:
The DimensionalityReduction package is deprecated. It is superseded by a new package MultivariateStats.
The package does not work on recent versions of Julia and will not be updated to do so in the future. Use MultivariateStats instead.

"object not found" error when creating a new geom for a package

Full disclosure: this issue is duplicated on the ggplot2 google group
I'm developing a package that makes heavy use of ggplot2. I've created my own geom—geom_rug_alt—as a way of putting rug fringes on the top/right of the plot instead of the default locations.
My problem is that when geom_rug_alt() is defined and called within a single script, it seems to plot just fine. (Please try it yourself to verify that.) But, in my package geom_rug_alt() is defined in one file (CommonFunctions.R) and called in another (the Residuals() function of larger function foo.R). When I call foo.R on something, I get this error:
Error in geom_rug_alt(aes(x = NULL, y = within.group.residuals, color = factor(within.1.sd.of.the.mean.of.all.residuals)), :
object 'GeomRugAlt' not found
Now, I've done a couple of things (suggested by Hadley in this thread) to try to make sure that geom_rug_alt() should work properly within the package:
I define GeomRugAlt as a proto object in a file essentially called CommonFunctions.R within my package. CommonFunctions.R contains lines 3-42 of my example script.
In CommonFunctions.R, I was sure to include the build_accessor() line for geom_rug_alt (line 42 in my example script) after the definition of GeomRugAlt
In the package DESCRIPTION file, I have a collate: line where CommonFunctions.R appears first
In the package DESCRIPTION file, I have a LazyLoad: false line
In CommonFunctions.R, I included a require(ggplot2) call before defining GeomRugAlt as a proto object.
In foo.R, I included a require(ggplot2) call before calling geom_rug_alt() within Residuals().
I'm not sure what else I'm missing. Given that my example script runs just fine, I suspect the issue isn't that my geom doesn't work, but that I'm doing something wrong as part of the package development process.
Sorry for duplicating the issue, but I can't seem to find a thorough solution to the problem :-(
Put export(GeomRugAlt) in the NAMESPACE file.

Resources