18
18
namask (ri:: RVector{Int32} ) = [i == R_NA_INT32 for i in ri. data]
19
19
namask (rn:: RNumericVector ) = map (isna_float64, reinterpret (UInt64, rn. data))
20
20
# if re or im is NA, the whole complex number is NA
21
- # FIXME avoid temporary Vector{Bool}
22
21
namask (rc:: RComplexVector ) = [isna_float64 (v. re) || isna_float64 (v. im) for v in reinterpret (Complex{UInt64}, rc. data)]
23
22
namask (rv:: RNullableVector ) = rv. na
24
23
@@ -38,12 +37,13 @@ function julia_vector(rl::RLogicalVector, force_nullable::Bool)
38
37
end
39
38
40
39
# converts Vector{Int32} into Vector{R} replacing R_NA_INT32 with 0
41
- na2zero {R} (:: Type{R} , v:: Vector{Int32} ) = [x != R_NA_INT32 ? R (x) : zero (R) for x in v]
40
+ # it's assumed that v fits into R
41
+ na2zero {R} (:: Type{R} , v:: Vector{Int32} ) = [ifelse (x != R_NA_INT32, x % R, zero (R)) for x in v]
42
42
43
- # convert to [Nullable]CategoricalArray{String} if `ri`is a factor,
43
+ # convert to [Nullable]CategoricalArray{String} if `ri` is a factor,
44
44
# or to [Nullable]Array{Int32} otherwise
45
45
function julia_vector (ri:: RIntegerVector , force_nullable:: Bool )
46
- ! isfactor (ri) && return _julia_vector (eltype (ri. data), ri, force_nullable) # not a factor
46
+ isfactor (ri) || return _julia_vector (eltype (ri. data), ri, force_nullable)
47
47
48
48
# convert factor into [Nullable]CategoricalArray
49
49
rlevels = getattr (ri, " levels" , emptystrvec)
@@ -55,9 +55,11 @@ function julia_vector(ri::RIntegerVector, force_nullable::Bool)
55
55
# FIXME set ordered flag
56
56
refs = na2zero (REFTYPE, ri. data)
57
57
pool = CategoricalPool {String, REFTYPE} (rlevels)
58
- (force_nullable || (findfirst (refs, zero (REFTYPE)) > 0 )) ?
59
- NullableCategoricalArray {String, 1, REFTYPE} (refs, pool) :
60
- CategoricalArray {String, 1, REFTYPE} (refs, pool)
58
+ if force_nullable || (findfirst (refs, zero (REFTYPE)) > 0 )
59
+ return NullableCategoricalArray {String, 1, REFTYPE} (refs, pool)
60
+ else
61
+ return CategoricalArray {String, 1, REFTYPE} (refs, pool)
62
+ end
61
63
end
62
64
63
65
function sexp2julia (rex:: RSEXPREC )
0 commit comments