Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Julia v0.6 #32

Merged
merged 9 commits into from
Nov 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ os:
- linux
- osx
julia:
- 0.5
- 0.6
- nightly
notifications:
email: false
Expand Down
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## RData v0.1.0 Release Notes

Updated to Julia v0.6 (older versions not supported).

##### Changes
* R logical vectors are converted to `DataVector{Bool}` (instead of `DataVector{Int32}`) [#32]
* dropped compatibility with Julia versions prior v0.6 [#32]

[#32]: https://github.com/JuliaStats/RData.jl/issues/32

## RData v0.0.4 Release Notes

Now the recommended way to load `.RData`/`.rda` files is by `FileIO.load()`.
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# RData

[![Julia 0.4 Status](http://pkg.julialang.org/badges/RData_0.4.svg)](http://pkg.julialang.org/?pkg=RData&ver=0.4)
[![Julia 0.5 Status](http://pkg.julialang.org/badges/RData_0.5.svg)](http://pkg.julialang.org/?pkg=RData&ver=0.5)
[![Julia 0.6 Status](http://pkg.julialang.org/badges/RData_0.6.svg)](http://pkg.julialang.org/?pkg=RData&ver=0.6)

[![Coverage Status](https://coveralls.io/repos/github/JuliaStats/RData.jl/badge.svg)](https://coveralls.io/github/JuliaStats/RData.jl)
[![Build Status](https://travis-ci.org/JuliaStats/RData.jl.svg?branch=master)](https://travis-ci.org/JuliaStats/RData.jl)
Expand Down
7 changes: 3 additions & 4 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
julia 0.5
DataFrames 0.7
DataArrays 0.3
julia 0.6
DataFrames 0.9
DataArrays 0.4
FileIO 0.1.2
GZip 0.2
Compat 0.17
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

Expand Down
10 changes: 5 additions & 5 deletions src/DictoVec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ function name2index(names::Vector{RString})
end

"""
Container that mimics R vector behaviour.
Elements could be accessed either by indices as a normal vector,
or (optionally) by string keys as a dictionary.
Container that mimics R vector behaviour.
Elements could be accessed either by indices as a normal vector,
or (optionally) by string keys as a dictionary.
"""
immutable DictoVec{T}
struct DictoVec{T}
data::T
name2index::Dict{RString, Int}
index2name::Dict{Int, RString}

@compat function (::Type{DictoVec}){T}(data::T, names::Vector{RString} = Vector{RString}())
function (::Type{DictoVec})(data::T, names::Vector{RString} = Vector{RString}()) where T
n2i, i2n = name2index(names)
new{T}(data, n2i, i2n)
end
Expand Down
6 changes: 2 additions & 4 deletions src/RData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ __precompile__()

module RData

using Compat, DataFrames, GZip, FileIO
import DataArrays: data
using DataFrames, DataArrays, GZip, FileIO
import DataFrames: identifier
import Compat: unsafe_string
import FileIO: load

export
Expand All @@ -19,7 +17,7 @@ include("sxtypes.jl")
"""
Abstract RDA format IO stream wrapper.
"""
@compat abstract type RDAIO end
abstract type RDAIO end

include("io/XDRIO.jl")
include("io/ASCIIIO.jl")
Expand Down
6 changes: 3 additions & 3 deletions src/config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
##############################################################################

"""
Non-standard addition to NaN bit pattern to discriminate NA from NaN.
0x000007a2 == UInt32(1954)
(I assume 1954 is the year of Ross's birth or something like that.)
Non-standard addition to NaN bit pattern to discriminate NA from NaN.
0x000007a2 == UInt32(1954)
(I assume 1954 is the year of Ross's birth or something like that.)
"""
const R_NA_FLOAT64_LOW = 0x000007a2

Expand Down
14 changes: 8 additions & 6 deletions src/context.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
RDA (R data archive) reading context.
RDA (R data archive) reading context.

* Stores flags that define how R objects are read and converted into Julia objects.
* Maintains the list of R objects that could be referenced later in the RDA stream.
"""
type RDAContext{T<:RDAIO}
struct RDAContext{T<:RDAIO}
io::T # RDA input stream

# RDA format properties
Expand All @@ -17,8 +17,10 @@ type RDAContext{T<:RDAIO}
# intermediate data
ref_tab::Vector{RSEXPREC} # SEXP array for references
end

int2ver(v::Integer) = VersionNumber(v >> 16, (v >> 8) & 0xff, v & 0xff)
function RDAContext{T<:RDAIO}(io::T, kwoptions::Vector{Any}=Any[])

function RDAContext(io::RDAIO, kwoptions::Vector{Any}=Any[])
fmtver = readuint32(io)
rver = int2ver(readint32(io))
rminver = int2ver(readint32(io))
Expand All @@ -27,10 +29,10 @@ function RDAContext{T<:RDAIO}(io::T, kwoptions::Vector{Any}=Any[])
end

"""
Registers R object, so that it could be referenced later
(by its index in the reference table).
Register R object, so that it could be referenced later
(by its index in the reference table).
"""
function registerref(ctx::RDAContext, obj::RSEXPREC)
function registerref!(ctx::RDAContext, obj::RSEXPREC)
push!(ctx.ref_tab, obj)
obj
end
4 changes: 4 additions & 0 deletions src/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ function DataArrays.data(ri::RIntegerVector)
return PooledDataArray(DataArrays.RefArray(refs), pool)
end

# convert R logical vector (uses Int32 to store values) into DataVector{Bool}
DataArrays.data(rl::RLogicalVector) =
return DataArray(Bool[x != 0 for x in rl.data], namask(rl))

function sexp2julia(rex::RSEXPREC)
warn("Conversion of $(typeof(rex)) to Julia is not implemented")
return nothing
Expand Down
6 changes: 3 additions & 3 deletions src/io/ASCIIIO.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
ASCII RData format IO stream wrapper.
ASCII RData format IO stream wrapper.
"""
type ASCIIIO{T<:IO} <: RDAIO
struct ASCIIIO{T<:IO} <: RDAIO
sub::T # underlying IO stream

(::Type{ASCIIIO}){T<:IO}(io::T) = new{T}(io)
(::Type{ASCIIIO})(io::T) where {T<:IO} = new{T}(io)
end

readint32(io::ASCIIIO) = parse(Int32, readline(io.sub))
Expand Down
8 changes: 4 additions & 4 deletions src/io/NativeIO.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
Native binary RData format IO stream wrapper.
Native binary RData format IO stream wrapper.

TODO write readers
TODO write readers
"""
type NativeIO{T<:IO} <: RDAIO
struct NativeIO{T<:IO} <: RDAIO
sub::T # underlying IO stream
(::Type{NativeIO}){T<:IO}(io::T) = new{T}(io)
(::Type{NativeIO})(io::T) where {T<:IO} = new{T}(io)
end
8 changes: 4 additions & 4 deletions src/io/XDRIO.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
XDR (machine-independent binary) RData format IO stream wrapper.
XDR (machine-independent binary) RData format IO stream wrapper.
"""
type XDRIO{T<:IO} <: RDAIO
struct XDRIO{T<:IO} <: RDAIO
sub::T # underlying IO stream
buf::Vector{UInt8} # buffer for strings
@compat (::Type{XDRIO}){T <: IO}(io::T) = new{T}(io, Vector{UInt8}(1024))
(::Type{XDRIO})(io::T) where {T <: IO} = new{T}(io, Vector{UInt8}(1024))
end

readint32(io::XDRIO) = ntoh(read(io.sub, Int32))
Expand All @@ -25,7 +25,7 @@ function readfloatorNA(io::XDRIO, n::RVecLength)
reinterpret(Float64, map!(ntoh, v, v))
end

readuint8(io::XDRIO, n::RVecLength) = readbytes(io.sub, n)
readuint8(io::XDRIO, n::RVecLength) = read(io.sub, UInt8, n)

function readnchars(io::XDRIO, n::Int32) # a single character string
readbytes!(io.sub, io.buf, n)
Expand Down
12 changes: 6 additions & 6 deletions src/io/utils.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
Creates `RDAIO` wrapper for `io` stream depending on its format
specified by `formatcode`.
Creates `RDAIO` wrapper for `io` stream depending on its format
specified by `formatcode`.
"""
function rdaio(io::IO, formatcode::AbstractString)
if formatcode == "X" XDRIO(io)
elseif formatcode == "A" ASCIIIO(io)
elseif formatcode == "B" NativeIO(io)
else error("Unrecognized RDA format \"$formatcode\"")
else throw(ArgumentError("Unrecognized RDA format \"$formatcode\""))
end
end

Expand Down Expand Up @@ -41,9 +41,9 @@ else
end
end

immutable CHARSXProps # RDA CHARSXP properties
levs::UInt32 # level flags (encoding etc) TODO process
nchar::Int32 # string length, -1 for NA strings
struct CHARSXProps # RDA CHARSXP properties
levs::UInt32 # level flags (encoding etc) TODO process
nchar::Int32 # string length, -1 for NA strings
end

function readcharsxprops(io::RDAIO) # read character string encoding and length
Expand Down
20 changes: 10 additions & 10 deletions src/readers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ end

function readsymbol(ctx::RDAContext, fl::RDATag)
@assert sxtype(fl) == SYMSXP
registerref(ctx, RSymbol(readcharacter(ctx.io)))
registerref!(ctx, RSymbol(readcharacter(ctx.io)))
end

function readS4(ctx::RDAContext, fl::RDATag)
Expand All @@ -78,7 +78,7 @@ end
function readenv(ctx::RDAContext, fl::RDATag)
@assert sxtype(fl) == ENVSXP
is_locked = readint32(ctx.io)
res = registerref(ctx, REnvironment()) # registering before reading the contents
res = registerref!(ctx, REnvironment()) # registering before reading the contents
res.enclosed = readitem(ctx)
res.frame = readitem(ctx)
res.hashtab = readitem(ctx)
Expand All @@ -98,12 +98,12 @@ end

function readnamespace(ctx::RDAContext, fl::RDATag)
@assert sxtype(fl) == NAMESPACESXP
registerref(ctx, RNamespace(readname(ctx)))
registerref!(ctx, RNamespace(readname(ctx)))
end

function readpackage(ctx::RDAContext, fl::RDATag)
@assert sxtype(fl) == PACKAGESXP
registerref(ctx, RPackage(readname(ctx)))
registerref!(ctx, RPackage(readname(ctx)))
end

# reads single-linked lists R objects
Expand Down Expand Up @@ -170,17 +170,17 @@ end

function readextptr(ctx::RDAContext, fl::RDATag)
@assert sxtype(fl) == EXTPTRSXP
res = registerref(ctx, RExtPtr()) # registering before reading the contents
res = registerref!(ctx, RExtPtr()) # registering before reading the contents
res.protected = readitem(ctx)
res.tag = readitem(ctx)
res.attr = readattrs(ctx, fl)
return res
end

"""
Context for reading R bytecode.
Context for reading R bytecode.
"""
immutable BytecodeContext
struct BytecodeContext
ctx::RDAContext # parent RDA context
ref_tab::Vector{Any} # table of bytecode references

Expand Down Expand Up @@ -251,15 +251,15 @@ function readunsupported(ctx::RDAContext, fl::RDATag)
end

"""
Definition of R type.
Definition of R type.
"""
immutable SXTypeInfo
struct SXTypeInfo
name::String # R type name
reader::Function # function to deserialize R type from RDA stream
end

"""
Maps R type id (`SXType`) to its `SXTypeInfo`.
Maps R type id (`SXType`) to its `SXTypeInfo`.
"""
const SXTypes = Dict{SXType, SXTypeInfo}(
NILSXP => SXTypeInfo("NULL",readdummy),
Expand Down