Reputation: 545
I am creating a function in Julia. It takes a dataframe (called window) and two strings (A and B) as inputs and subsets it using the variables given:
function calcs(window, A, B):
fAB=size(window[(window[:ref].==A).&(window[:alt].==B),:])[1]
end
But I get the error:
syntax: invalid assignment location ":fAB"
Stacktrace:
[1] include_string(::String, ::String) at ./loading.jl:522
I have tried running the code outside of a function (having pre-assigned the variables A="T"
and B="C"
like so:
fAB=size(window[(window[:ref].==A).&(window[:alt].==B),:])[1]
and this runs fine. I am new to Julia but cannot find an answer to this question. Can anyone help?
Upvotes: 1
Views: 1479
Reputation: 69819
Seems you come from Python world. In Julia you do not need to add :
in function definition. This will go through fine:
function calcs(window, A, B)
fAB=size(window[(window[:ref].==A).&(window[:alt].==B),:])[1]
end
When Julia encounters :
in the first line of function definition it continues parsing the expression in the following line producing :fAB
symbol.
EDIT: In Julia 0.7 this problem is detected by the parser. This is the result of copy-pasting your original code to REPL:
julia> function calcs(window, A, B):
fAB=size(window[(window[:ref].==A).&(window[:alt].==B),:])[1]
ERROR: syntax: space not allowed after ":" used for quoting
julia> end
ERROR: syntax: unexpected "end"
Upvotes: 4