# Macros don't seem to work?

**URL:** https://discourse.julialang.org/t/macros-dont-seem-to-work/5111
**Category:** New to Julia
**Created:** [July 28, 2017, 11:30am UTC](https://discourse.julialang.org/t/macros-dont-seem-to-work/5111 "2017-07-28T11:30:28Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![LotteVictor](https://avatars.discourse-cdn.com/v4/letter/l/b19c9b/32.png) [@LotteVictor](https://discourse.julialang.org/u/LotteVictor)
#### Post date: [July 28, 2017, 11:30am UTC](https://discourse.julialang.org/t/macros-dont-seem-to-work/5111/1 "2017-07-28T11:30:28Z")

</div>

I’m new to Julia and trying to use some macros of Query.jl. I’m running Julia v0.6 in Juno on Linux Mint Cinnamon 18.1, 64bit. Macros don’t seem to work, I always get errors e.g.:

`A=collect(1:10) '@where !=5 MethodError: no method matching @where(::Expr)`

It makes no difference, which macro I’m using, they all throw this error. Did anybody ever encounter that before? I would guess, it’S something to do with my installation, but I don’t know, how to find that out. I already tried `Pkg.update()` and no packages need to be updated…  
Thanks!

---

<div class="post-metadata">

### Author: ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)
#### Post date: [July 28, 2017, 12:04pm UTC](https://discourse.julialang.org/t/macros-dont-seem-to-work/5111/2 "2017-07-28T12:04:47Z")

</div>

I don’t believe `@where` is a macro. It’s not listed in [https://github.com/JuliaLang/julia/blob/master/base/exports.jl](https://github.com/JuliaLang/julia/blob/master/base/exports.jl) Do you mean `@which`?

```julia
julia> @which 4!=5
!=(x, y) in Base at operators.jl:129

julia> @where 4!=5
ERROR: UndefVarError: @where not defined

```

julia-0.6.0 generic binary, running on opensuse tumbleweed.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [July 28, 2017, 12:05pm UTC](https://discourse.julialang.org/t/macros-dont-seem-to-work/5111/3 "2017-07-28T12:05:54Z")

</div>

`@where` is defined in Query.jl. It is documented here: [http://www.david-anthoff.com/Query.jl/stable/querycommands.html#Filtering-1](http://www.david-anthoff.com/Query.jl/stable/querycommands.html#Filtering-1). It never uses the syntax in your post. Also, I think you should apply it to sources like dataframes and not to a vector.

Could you say more clearly what you actually want to do?

---

<div class="post-metadata">

### Author: ![LotteVictor](https://avatars.discourse-cdn.com/v4/letter/l/b19c9b/32.png) [@LotteVictor](https://discourse.julialang.org/u/LotteVictor)
#### Post date: [July 28, 2017, 12:11pm UTC](https://discourse.julialang.org/t/macros-dont-seem-to-work/5111/4 "2017-07-28T12:11:03Z")

</div>

Thanks, but I#m not so sure, whether it’s a syntactic problem, because I get the same error, when trying @from (from the Query) package. I’m actually trying to do pretty much the same as in the example given there. The data I’m trying to use this on is also a DataFrame, however I only want to get certain values out if the first column, so it might be treated like a vector? I’m not so sure, how htis is in Julia. in R, I would use which().

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [July 28, 2017, 12:12pm UTC](https://discourse.julialang.org/t/macros-dont-seem-to-work/5111/5 "2017-07-28T12:12:34Z")

</div>

Can you give a minimal example, using a dataframe, the code that you execute on that dataframe, what result you expect to get, and the errors printed?

---

<div class="post-metadata">

### Author: ![LotteVictor](https://avatars.discourse-cdn.com/v4/letter/l/b19c9b/32.png) [@LotteVictor](https://discourse.julialang.org/u/LotteVictor)
#### Post date: [July 28, 2017, 12:13pm UTC](https://discourse.julialang.org/t/macros-dont-seem-to-work/5111/6 "2017-07-28T12:13:51Z")

</div>

Thanks! I tried `@which` and it works! So my guess is, the installation of the Query package didn’t work properly. I used Pkg.add() and then updated it with `Pkg.update()`. Is this the correct way or is there a difference between installing packages in the REPL and in Juno?

---

<div class="post-metadata">

### Author: ![LotteVictor](https://avatars.discourse-cdn.com/v4/letter/l/b19c9b/32.png) [@LotteVictor](https://discourse.julialang.org/u/LotteVictor)
#### Post date: [July 28, 2017, 12:19pm UTC](https://discourse.julialang.org/t/macros-dont-seem-to-work/5111/7 "2017-07-28T12:19:34Z")

</div>

Of course!

`using Distributions`  
`using DataFrames`  
`using Query`  
`Adult_h_ind=DataFrame(Float64, 100, 100)`  
`Adult_h_ind[1:20,1]=rand(Normal(10, 2), 20)`  
`NotNA= Query.@from i in Adult_h_ind[1] begin`  
` Query.@where Adult_h_ind[1] != NA`  
` end`

edit to add the error message:

`MethodError: no method matching @from(::Expr)`  
`Closest candidates are:`  
`@from(::Expr, !Matched::Expr) at /home/gast/.julia/v0.6/Query/src/Query.jl:47`  
`include_string(::String, ::String) at loading.jl:515`  
`eval(::Module, ::Any) at boot.jl:235`  
`(::Atom.##61#64)() at eval.jl:102`  
`withpath(::Atom.##61#64, ::Void) at utils.jl:30`  
`withpath(::Function, ::Void) at eval.jl:38`  
`macro expansion at eval.jl:101 [inlined]`  
`(::Atom.##60#63{Dict{String,Any}})() at task.jl:80`

I also tried shorter syntax, both in Juno and the REPL, with only one of the macros and I always got the method error… The other packages (like Distributions) work fine…

---

<div class="post-metadata">

### Author: ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)
#### Post date: [July 28, 2017, 12:20pm UTC](https://discourse.julialang.org/t/macros-dont-seem-to-work/5111/8 "2017-07-28T12:20:56Z")

</div>

Glad to hear. That’s the stantard incantation from the REPL. I don’t use Juno so can’t say with authority, but I’d be surprised if it were different there.

```julia
julia> Pkg.add("Query")
julia> Pkg.update()
julia> using Query
julia> @which 4!=3
!=(x, y) in Base at operators.jl:129

```

---

<div class="post-metadata">

### Author: ![LotteVictor](https://avatars.discourse-cdn.com/v4/letter/l/b19c9b/32.png) [@LotteVictor](https://discourse.julialang.org/u/LotteVictor)
#### Post date: [July 28, 2017, 12:28pm UTC](https://discourse.julialang.org/t/macros-dont-seem-to-work/5111/9 "2017-07-28T12:28:12Z")

</div>

Short question on the side: when using @which the result is something like !=(x,y) in Base at operators.jl:129. How do I get either the actual values or the indices of that parts of arrays that match the question?  
e.g. `A= collect(1:10), @which A != 5`  
and the answer I’m searching for is something like 1,2,3,4,6,7,8,9,10?  
Thanks!

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [July 28, 2017, 12:31pm UTC](https://discourse.julialang.org/t/macros-dont-seem-to-work/5111/10 "2017-07-28T12:31:19Z")

</div>

I don’t think you want `@which`.

```julia
help?> @which
  @which

  Applied to a function or macro call, it evaluates the arguments to the
  specified call, and returns the Method object for the method that would be
  called for those arguments. Applied to a variable, it returns the module in
  which the variable was bound. It calls out to the which function.

```

For an array you can use `find`

```julia
julia> find(x -> x != 5, A)
9-element Array{Int64,1}:
  1
  2
  3
  4
  6
  7
  8
  9
 10

```

---

<div class="post-metadata">

### Author: ![LotteVictor](https://avatars.discourse-cdn.com/v4/letter/l/b19c9b/32.png) [@LotteVictor](https://discourse.julialang.org/u/LotteVictor)
#### Post date: [July 28, 2017, 12:37pm UTC](https://discourse.julialang.org/t/macros-dont-seem-to-work/5111/11 "2017-07-28T12:37:33Z")

</div>

Thanks! I’ll try to use find. I don’t know, what’s up with my Query package, but I think, with your help, i can work around it, hopefully…  
Thanks a lot!

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [July 28, 2017, 12:46pm UTC](https://discourse.julialang.org/t/macros-dont-seem-to-work/5111/12 "2017-07-28T12:46:51Z")

</div>

Please quote your code.

From the [doc](http://www.david-anthoff.com/Query.jl/stable/querycommands.html#Filtering-1) `@where` is not a standalone macro so you must not use it like that.

---

<div class="post-metadata">

### Author: ![LotteVictor](https://avatars.discourse-cdn.com/v4/letter/l/b19c9b/32.png) [@LotteVictor](https://discourse.julialang.org/u/LotteVictor)
#### Post date: [July 28, 2017, 1:10pm UTC](https://discourse.julialang.org/t/macros-dont-seem-to-work/5111/13 "2017-07-28T13:10:10Z")

</div>

I showed my quote in the above answer. If I understand you correctly, `@select` and `@collect` are necessary to use the `@where` macro correctly? Or is it less than that? Where do I generally find information such as that, that there a requirements for macros, except for the examples? The error messages are not really that helpful in this… Thanks!

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [July 28, 2017, 1:12pm UTC](https://discourse.julialang.org/t/macros-dont-seem-to-work/5111/14 "2017-07-28T13:12:58Z")

</div>

Error messages on macro based API are typically quite unhelpful unless the author of them does careful syntax checking. You need to just read the docs for macros and look at examples.

---

<div class="post-metadata">

### Author: ![LotteVictor](https://avatars.discourse-cdn.com/v4/letter/l/b19c9b/32.png) [@LotteVictor](https://discourse.julialang.org/u/LotteVictor)
#### Post date: [July 28, 2017, 1:17pm UTC](https://discourse.julialang.org/t/macros-dont-seem-to-work/5111/15 "2017-07-28T13:17:29Z")

</div>

Thanks! I’ll keep that in mind!

---

<div class="post-metadata">

### Author: ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)
#### Post date: [July 28, 2017, 1:22pm UTC](https://discourse.julialang.org/t/macros-dont-seem-to-work/5111/16 "2017-07-28T13:22:09Z")

</div>

Quoting your code: Whenever you include code in your posts, put it between double or triple back single quotes so that it’s formatted nicely, e.g.

```julia
julia> @which 4+5
+(x::T, y::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8} in Base at int.jl:32

```

About `@where`, reread @kristoffer.carlsson’s post. It looks like you want to use `find`, not `@where`

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [July 28, 2017, 1:32pm UTC](https://discourse.julialang.org/t/macros-dont-seem-to-work/5111/17 "2017-07-28T13:32:51Z")

</div>

> [@LotteVictor](#):
>
> I showed my quote in the above answer.

I mean quote the code you quote with `````. It’s very hard to read if you compare to what other people post.

> [@LotteVictor](#):
>
> If I understand you correctly, @select and @collect are necessary to use the @ where macro correctly?

yes, according to the doc

---

<div class="post-metadata">

### Author: ![LotteVictor](https://avatars.discourse-cdn.com/v4/letter/l/b19c9b/32.png) [@LotteVictor](https://discourse.julialang.org/u/LotteVictor)
#### Post date: [July 28, 2017, 2:09pm UTC](https://discourse.julialang.org/t/macros-dont-seem-to-work/5111/18 "2017-07-28T14:09:24Z")

</div>

Thanks! I wasn’t sure how the formatting works here! Now I know! For my purposes `find()` will do fine! Thanks @kristoffer.carlsson and @John_Gibson! Everything else was a great learning opportunity for me, thanks again!
