5
5
function _writevalue (io:: IO , value:: AbstractString , delim, quotechar, escapechar, nastring)
6
6
print (io, quotechar)
7
7
for c in value
8
- if c== quotechar || c== escapechar
8
+ if c == quotechar || c == escapechar
9
9
print (io, escapechar)
10
10
end
11
11
print (io, c)
32
32
push_exprs = Expr (:block )
33
33
for i in 1 : n
34
34
push! (push_exprs. args, :( _writevalue (io, i.$ (col_names[i]), delim, quotechar, escapechar, nastring) ))
35
- if i< n
36
- push! (push_exprs. args, :( print (io, delim ) ))
35
+ if i < n
36
+ push! (push_exprs. args, :( print (io, delim) ))
37
37
end
38
38
end
39
39
push! (push_exprs. args, :( println (io) ))
45
45
end
46
46
end
47
47
48
- function _save (io, data; delim= ' ,' , quotechar= ' "' , escapechar= ' "' , nastring= " NA" , header= true )
48
+ function _save (io, data; delim = ' ,' , quotechar = ' "' , escapechar = ' "' , nastring = " NA" , header = true )
49
49
isiterabletable (data) || error (" Can't write this data to a CSV file." )
50
50
51
51
it = getiterator (data)
52
52
colnames = collect (eltype (it). parameters[1 ])
53
53
54
54
if header
55
- if quotechar=== nothing
56
- join (io,[string (colname) for colname in colnames],delim)
55
+ if quotechar === nothing
56
+ join (io, [string (colname) for colname in colnames], delim)
57
57
else
58
- join (io,[" $(quotechar) " * replace (string (colname), quotechar => " $(escapechar)$(quotechar) " ) * " $(quotechar) " for colname in colnames],delim)
58
+ join (io, [" $(quotechar) " * replace (string (colname), quotechar => " $(escapechar)$(quotechar) " ) * " $(quotechar) " for colname in colnames], delim)
59
59
end
60
60
println (io)
61
61
end
62
62
_writecsv (io, it, eltype (it), delim, quotechar, escapechar, nastring)
63
63
end
64
64
65
- function _save (filename:: AbstractString , data; delim= ' ,' , quotechar= ' "' , escapechar= ' "' , nastring= " NA" , header= true )
65
+ function _save (filename:: AbstractString , data; delim = ' ,' , quotechar = ' "' , escapechar = ' "' , nastring = " NA" , header = true )
66
66
isiterabletable (data) || error (" Can't write this data to a CSV file." )
67
67
68
68
ext = last (split (filename, ' .' ))
69
69
70
70
if ext == " gz" # Gzipped
71
71
open (GzipCompressorStream, filename, " w" ) do io
72
- _save (io, data, delim= delim, quotechar= quotechar, escapechar= escapechar, nastring= nastring, header= header)
72
+ _save (io, data, delim = delim, quotechar = quotechar, escapechar = escapechar, nastring = nastring, header = header)
73
73
end
74
74
else
75
75
open (filename, " w" ) do io
76
- _save (io, data, delim= delim, quotechar= quotechar, escapechar= escapechar, nastring= nastring, header= header)
76
+ _save (io, data, delim = delim, quotechar = quotechar, escapechar = escapechar, nastring = nastring, header = header)
77
77
end
78
78
end
79
79
end
80
80
81
81
82
82
83
- function fileio_save (f:: FileIO.File{FileIO.format"CSV"} , data; delim= ' ,' , quotechar= ' "' , escapechar= ' "' , nastring= " NA" , header= true )
84
- return _save (f. filename, data, delim= delim, quotechar= quotechar, escapechar= escapechar, nastring= nastring, header= header)
83
+ function fileio_save (f:: FileIO.File{FileIO.format"CSV"} , data; delim = ' ,' , quotechar = ' "' , escapechar = ' "' , nastring = " NA" , header = true )
84
+ return _save (f. filename, data, delim = delim, quotechar = quotechar, escapechar = escapechar, nastring = nastring, header = header)
85
85
end
86
86
87
- function fileio_save (f:: FileIO.File{FileIO.format"TSV"} , data; delim= ' \t ' , quotechar= ' "' , escapechar= ' "' , nastring= " NA" , header= true )
88
- return _save (f. filename, data, delim= delim, quotechar= quotechar, escapechar= escapechar, nastring= nastring, header= header)
87
+ function fileio_save (f:: FileIO.File{FileIO.format"TSV"} , data; delim = ' \t ' , quotechar = ' "' , escapechar = ' "' , nastring = " NA" , header = true )
88
+ return _save (f. filename, data, delim = delim, quotechar = quotechar, escapechar = escapechar, nastring = nastring, header = header)
89
89
end
90
90
91
- function fileio_save (s:: FileIO.Stream{FileIO.format"CSV"} , data; delim= ' ,' , quotechar= ' "' , escapechar= ' "' , nastring= " NA" , header= true )
92
- return _save (s. io, data, delim= delim, quotechar= quotechar, escapechar= escapechar, nastring= nastring, header= header)
91
+ function fileio_save (s:: FileIO.Stream{FileIO.format"CSV"} , data; delim = ' ,' , quotechar = ' "' , escapechar = ' "' , nastring = " NA" , header = true )
92
+ return _save (s. io, data, delim = delim, quotechar = quotechar, escapechar = escapechar, nastring = nastring, header = header)
93
93
end
94
94
95
- function fileio_save (s:: FileIO.Stream{FileIO.format"TSV"} , data; delim= ' \t ' , quotechar= ' "' , escapechar= ' "' , nastring= " NA" , header= true )
96
- return _save (s. io, data, delim= delim, quotechar= quotechar, escapechar= escapechar, nastring= nastring, header= header)
95
+ function fileio_save (s:: FileIO.Stream{FileIO.format"TSV"} , data; delim = ' \t ' , quotechar = ' "' , escapechar = ' "' , nastring = " NA" , header = true )
96
+ return _save (s. io, data, delim = delim, quotechar = quotechar, escapechar = escapechar, nastring = nastring, header = header)
97
97
end
98
98
99
99
#
100
100
# Streaming version writes header (if any) on first call, then appends on subsequent calls.
101
101
#
102
- const CSV_or_TSV = Union{FileIO. format " CSV" , FileIO. format " TSV" }
102
+ const CSV_or_TSV = Union{FileIO. format " CSV" ,FileIO. format " TSV" }
103
103
104
104
_delim (T) = T <: FileIO.format"CSV" ? ' ,' : ' \t '
105
105
@@ -112,30 +112,30 @@ mutable struct CSVFileSaveStream{T}
112
112
nastring:: AbstractString
113
113
header:: Bool
114
114
end
115
-
116
- function fileio_savestreaming (f:: FileIO.File{T} , data= nothing ; delim= _delim (T), quotechar= ' "' , escapechar= ' "' , nastring= " NA" ,
117
- header= true ) where T <: CSV_or_TSV
115
+
116
+ function fileio_savestreaming (f:: FileIO.File{T} , data = nothing ; delim = _delim (T), quotechar = ' "' , escapechar = ' "' , nastring = " NA" ,
117
+ header = true ) where T <: CSV_or_TSV
118
118
io = open (f. filename, " w" )
119
119
120
- if data!= = nothing
121
- _save (io, data; delim= delim, quotechar= quotechar, escapechar= escapechar, nastring= nastring, header= header)
120
+ if data != = nothing
121
+ _save (io, data; delim = delim, quotechar = quotechar, escapechar = escapechar, nastring = nastring, header = header)
122
122
end
123
123
124
- return CSVFileSaveStream (io, data!= = nothing , delim, quotechar, escapechar, nastring, header)
124
+ return CSVFileSaveStream (io, data != = nothing , delim, quotechar, escapechar, nastring, header)
125
125
end
126
126
127
- function fileio_savestreaming (s:: FileIO.Stream{T} , data= nothing ; delim= _delim (T), quotechar= ' "' , escapechar= ' "' , nastring= " NA" ,
128
- header= false ) where T <: CSV_or_TSV
127
+ function fileio_savestreaming (s:: FileIO.Stream{T} , data = nothing ; delim = _delim (T), quotechar = ' "' , escapechar = ' "' , nastring = " NA" ,
128
+ header = false ) where T <: CSV_or_TSV
129
129
130
- if data!= = nothing
131
- _save (s. io, data; delim= delim, quotechar= quotechar, escapechar= escapechar, nastring= nastring, header= header)
130
+ if data != = nothing
131
+ _save (s. io, data; delim = delim, quotechar = quotechar, escapechar = escapechar, nastring = nastring, header = header)
132
132
end
133
-
134
- return CSVFileSaveStream (s. io, data!= = nothing , delim, quotechar, escapechar, nastring, header)
133
+
134
+ return CSVFileSaveStream (s. io, data != = nothing , delim, quotechar, escapechar, nastring, header)
135
135
end
136
136
137
137
function Base. write (s:: CSVFileSaveStream , data)
138
- _save (s. io, data; delim= s. delim, quotechar= s. quotechar, escapechar= s. escapechar, nastring= s. nastring, header= s. first_data_written ? false : header)
138
+ _save (s. io, data; delim = s. delim, quotechar = s. quotechar, escapechar = s. escapechar, nastring = s. nastring, header = s. first_data_written ? false : header)
139
139
end
140
140
141
141
function Base. close (s:: CSVFileSaveStream )
0 commit comments