From 2e46b2ff90b7b6452c34d0add5c85107e248ffa5 Mon Sep 17 00:00:00 2001 From: Andrew Janke Date: Sat, 3 Feb 2024 20:25:34 -0500 Subject: [PATCH] [style] use parens in if/while/switch predicates, space after "!", "!=" instead of "~=" --- .../+internal/+datasets/EuStockMarkets_1.m | 2 +- .../+internal/+datasets/airquality_1.m | 4 +- .../+internal/+datasets/anscombe_1.m | 4 +- .../+examples/+internal/+datasets/cars_1.m | 6 +- .../+examples/+internal/+datasets/cupcake_1.m | 4 +- .../+examples/+internal/+datasets/freeny_1.m | 2 +- inst/+tblish/+examples/SpDb.m | 2 +- inst/+tblish/+examples/coplot.m | 14 +- .../+examples/peel_off_name_value_options.m | 10 +- inst/+tblish/+examples/plot_pairs.m | 18 +- .../private/peelOffNameValueOptions.m | 2 +- .../+examples/run_all_example_scripts.m | 2 +- .../+internal/+chrono/+algo/binsearch.m | 18 +- .../+internal/+chrono/+tzinfo/PosixZoneRule.m | 15 +- inst/+tblish/+internal/+chrono/+tzinfo/TzDb.m | 27 +- .../+internal/+chrono/+tzinfo/TzInfo.m | 40 +- .../+internal/+chrono/+tzinfo/TzZoneFile.m | 12 +- .../+tzinfo/WindowsIanaZoneConverter.m | 11 +- .../+chrono/+tzinfo/ZoneFileSectionParser.m | 18 +- .../+chrono/detect_system_timezone.m | 26 +- inst/+tblish/+internal/+chrono/findFiles.m | 3 +- .../+internal/+chrono/format_dispstr_array.m | 6 +- inst/+tblish/+internal/+chrono/mustBeIntVal.m | 4 +- inst/+tblish/+internal/+chrono/mustBeScalar.m | 4 +- inst/+tblish/+internal/+chrono/mycombvec.m | 4 +- .../+chrono/prefillNewSizeForSubsasgn.m | 26 +- .../+internal/+chrono/prettyprint_array.m | 8 +- inst/+tblish/+internal/+chrono/scalarexpand.m | 10 +- .../+internal/+chrono/slurpBinaryFile.m | 2 +- .../+tblish/+internal/+chrono/slurpTextFile.m | 2 +- inst/+tblish/+internal/+chrono/sprintfv.m | 16 +- inst/+tblish/+internal/+table/blankTable.m | 12 +- .../+tblish/+internal/+table/fillValForType.m | 10 +- .../+table/fillValForTypeCtorStyle.m | 14 +- .../+internal/+table/fillValForTypeGeneric.m | 2 +- inst/+tblish/+internal/+table/fillValForVal.m | 24 +- inst/+tblish/+internal/+table/gen_colvecfun.m | 4 +- inst/+tblish/+internal/+table/jndx2kndxs.m | 4 +- inst/+tblish/+internal/+table/matchrows.m | 10 +- inst/+tblish/+internal/+table/mx_summary.m | 10 +- .../+tblish/+internal/+table/vartype_filter.m | 8 +- inst/+tblish/+internal/cmp_versions.m | 28 +- inst/+tblish/+internal/dataset.m | 14 +- .../+internal/generate_datasets_list.m | 8 +- inst/+tblish/+internal/load_tablicious.m | 14 +- .../+internal/parse_ismissing_indicator.m | 10 +- inst/+tblish/+internal/splitapply_impl.m | 2 +- inst/+tblish/+internal/unload_tablicious.m | 14 +- inst/+tblish/dataset.m | 344 +++++----- inst/+tblish/datasets.m | 8 +- inst/NaC.m | 2 +- inst/NaS.m | 2 +- inst/NaT.m | 2 +- inst/array2table.m | 8 +- inst/calendarDuration.m | 116 ++-- inst/calmonths.m | 2 +- inst/calyears.m | 2 +- inst/categorical.m | 146 ++--- inst/cell2table.m | 16 +- inst/colvecfun.m | 4 +- inst/contains.m | 8 +- inst/datetime.m | 170 ++--- inst/days.m | 4 +- inst/discretize.m | 24 +- inst/dispstrs.m | 8 +- inst/duration.m | 138 ++-- inst/examples/tblish_ex_01_suppliers_parts.m | 12 +- inst/hours.m | 2 +- inst/iscalendarduration.m | 6 +- inst/iscategorical.m | 6 +- inst/isdatetime.m | 6 +- inst/isduration.m | 6 +- inst/isnanny.m | 12 +- inst/istable.m | 6 +- inst/localdate.m | 149 ++--- inst/milliseconds.m | 2 +- inst/minutes.m | 2 +- inst/missing.m | 35 +- inst/pp.m | 8 +- inst/private/format_dispstr_array.m | 8 +- inst/private/intersect_stable.m | 2 +- inst/private/mycombvec.m | 4 +- inst/private/peelOffNameValueOptions.m | 2 +- inst/private/prettyprint_array.m | 12 +- inst/private/sprintfv.m | 20 +- inst/proxykeysForMatrixes.m | 38 +- inst/scalarexpand.m | 10 +- inst/seconds.m | 2 +- inst/shims/compat/all/isstring.m | 2 +- inst/shims/compat/pre-5.0.0/isfile.m | 4 +- inst/shims/compat/pre-5.0.0/isfolder.m | 4 +- inst/shims/compat/pre-6.0.0/mustBeFinite.m | 8 +- inst/shims/compat/pre-6.0.0/mustBeInteger.m | 16 +- inst/shims/compat/pre-6.0.0/mustBeMember.m | 8 +- inst/shims/compat/pre-6.0.0/mustBeNonempty.m | 8 +- inst/shims/compat/pre-6.0.0/mustBeNumeric.m | 4 +- inst/shims/compat/pre-6.0.0/mustBeReal.m | 8 +- inst/shims/compat/pre-7.0.0/endsWith.m | 10 +- inst/shims/compat/pre-7.0.0/startsWith.m | 8 +- inst/string.m | 102 +-- inst/struct2table.m | 6 +- inst/table.m | 605 +++++++++--------- inst/timezones.m | 15 +- inst/validators/mustBeA.m | 8 +- inst/validators/mustBeCellstr.m | 10 +- inst/validators/mustBeCharvec.m | 8 +- inst/validators/mustBeSameSize.m | 14 +- inst/validators/mustBeScalar.m | 8 +- inst/validators/mustBeScalarLogical.m | 8 +- inst/validators/mustBeVector.m | 8 +- inst/vecfun.m | 2 +- inst/years.m | 2 +- octave_tablicious_make_local.m | 8 +- 113 files changed, 1384 insertions(+), 1364 deletions(-) diff --git a/inst/+tblish/+examples/+internal/+datasets/EuStockMarkets_1.m b/inst/+tblish/+examples/+internal/+datasets/EuStockMarkets_1.m index 9c86c93d..c32ffd3b 100644 --- a/inst/+tblish/+examples/+internal/+datasets/EuStockMarkets_1.m +++ b/inst/+tblish/+examples/+internal/+datasets/EuStockMarkets_1.m @@ -11,7 +11,7 @@ price0 = price(1,:); -rel_price = price ./ repmat (price0, [size(price,1) 1]); +rel_price = price ./ repmat (price0, [size(price, 1) 1]); figure; plot (day, rel_price); diff --git a/inst/+tblish/+examples/+internal/+datasets/airquality_1.m b/inst/+tblish/+examples/+internal/+datasets/airquality_1.m index ac4b9c72..6ce63ae9 100644 --- a/inst/+tblish/+examples/+internal/+datasets/airquality_1.m +++ b/inst/+tblish/+examples/+internal/+datasets/airquality_1.m @@ -5,10 +5,10 @@ figure; for i = 1:n_vars for j = 1:n_vars - if i == j + if (i == j) continue endif - ix_subplot = (n_vars*(j - 1) + i); + ix_subplot = (n_vars * (j - 1) + i); hax = subplot (n_vars, n_vars, ix_subplot); var_x = vars{i}; var_y = vars{j}; diff --git a/inst/+tblish/+examples/+internal/+datasets/anscombe_1.m b/inst/+tblish/+examples/+internal/+datasets/anscombe_1.m index 83d15ca4..48cba5e9 100644 --- a/inst/+tblish/+examples/+internal/+datasets/anscombe_1.m +++ b/inst/+tblish/+examples/+internal/+datasets/anscombe_1.m @@ -23,5 +23,5 @@ # Fiddle with the plot axes parameters linkaxes (haxs); -xlim(haxs(1), x_limits); -ylim(haxs(1), y_limits); +xlim (haxs(1), x_limits); +ylim (haxs(1), y_limits); diff --git a/inst/+tblish/+examples/+internal/+datasets/cars_1.m b/inst/+tblish/+examples/+internal/+datasets/cars_1.m index 000f1dbd..45735994 100644 --- a/inst/+tblish/+examples/+internal/+datasets/cars_1.m +++ b/inst/+tblish/+examples/+internal/+datasets/cars_1.m @@ -6,12 +6,12 @@ figure; plot (t.speed, t.dist, "o"); -xlabel ("Speed (mph)"); ylabel("Stopping distance (ft)"); +xlabel ("Speed (mph)"); ylabel ("Stopping distance (ft)"); title ("cars data"); figure; loglog (t.speed, t.dist, "o"); -xlabel ("Speed (mph)"); ylabel("Stopping distance (ft)"); +xlabel ("Speed (mph)"); ylabel ("Stopping distance (ft)"); title ("cars data (logarithmic scales)"); # TODO: Do the linear model plot @@ -19,7 +19,7 @@ # Polynomial regression figure; plot (t.speed, t.dist, "o"); -xlabel ("Speed (mph)"); ylabel("Stopping distance (ft)"); +xlabel ("Speed (mph)"); ylabel ("Stopping distance (ft)"); title ("cars polynomial regressions"); hold on xlim ([0 25]); diff --git a/inst/+tblish/+examples/+internal/+datasets/cupcake_1.m b/inst/+tblish/+examples/+internal/+datasets/cupcake_1.m index 7ff21fa4..f2b7ccb3 100644 --- a/inst/+tblish/+examples/+internal/+datasets/cupcake_1.m +++ b/inst/+tblish/+examples/+internal/+datasets/cupcake_1.m @@ -1,3 +1,3 @@ t = tblish.dataset.cupcake -plot(datenum(t.Month), t.Cupcake) -title ('“Cupcake” Google Searches'); xlabel ("Year"); ylabel ("Unknown popularity metric") +plot (datenum (t.Month), t.Cupcake) +title ('“Cupcake” Google Searches'); xlabel ("Year"); ylabel ("Unknown popularity metric"); diff --git a/inst/+tblish/+examples/+internal/+datasets/freeny_1.m b/inst/+tblish/+examples/+internal/+datasets/freeny_1.m index fd7d4b75..f4faaef8 100644 --- a/inst/+tblish/+examples/+internal/+datasets/freeny_1.m +++ b/inst/+tblish/+examples/+internal/+datasets/freeny_1.m @@ -1,6 +1,6 @@ t = tblish.dataset.freeny; -summary(t) +summary (t) tblish.examples.plot_pairs (removevars (t, "date")) diff --git a/inst/+tblish/+examples/SpDb.m b/inst/+tblish/+examples/SpDb.m index f59657dd..8b0a7f12 100644 --- a/inst/+tblish/+examples/SpDb.m +++ b/inst/+tblish/+examples/SpDb.m @@ -53,7 +53,7 @@ 'S4' 'P4' 300 'S4' 'P5' 400 }, 'VariableNames', {'SNum', 'PNum', 'Qty'}); - if nargout == 1 + if (nargout == 1) varargout = { struct('S', S, 'P', P, 'SP', SP) }; else varargout = { S, P, SP }; diff --git a/inst/+tblish/+examples/coplot.m b/inst/+tblish/+examples/coplot.m index f2a3eb2d..9b253d55 100644 --- a/inst/+tblish/+examples/coplot.m +++ b/inst/+tblish/+examples/coplot.m @@ -58,7 +58,7 @@ ## ## @end deftypefn -function [fig, hax] = coplot(varargin) +function [fig, hax] = coplot (varargin) narginchk (4, Inf); defaults = { "PlotFcn" "plot" @@ -70,10 +70,10 @@ "PlotArgs" {} }); mustBeA (opts.PlotFcn, "function_handle", "opts.PlotFcn"); - if ! iscell (opts.PlotArgs) + if (! iscell (opts.PlotArgs)) opts.PlotArgs = { opts.PlotArgs }; endif - if isnumeric (args{1}) + if (isnumeric (args{1})) fig = args{1}; mustBeScalar (fig); figure (fig); @@ -87,12 +87,12 @@ [X, x_name] = getvar (tbl, xvar); [Y, y_name] = getvar (tbl, yvar); [g_ix, g_names] = resolveVarRef (tbl, gvar); - if isscalar (g_ix) + if (isscalar (g_ix)) hax = coplot_one (fig, tbl, X, x_name, Y, y_name, g_ix, g_names, opts); else hax = coplot_two (fig, tbl, X, x_name, Y, y_name, g_ix, g_names, opts); endif - if nargout < 1 + if (nargout < 1) clear fig endif endfunction @@ -116,10 +116,10 @@ ix_row = ceil (i / n_cols); ix_col = 1 + rem (i, n_rows); ax = subplot (n_rows, n_cols, i); - if ix_col != 1 + if (ix_col != 1) set(ax, 'yticklabel', {}); endif - if ix_row != n_rows + if (ix_row != n_rows) set(ax, 'xticklabel', {}); endif set(ax, 'position', get(ax, 'outerposition')); diff --git a/inst/+tblish/+examples/peel_off_name_value_options.m b/inst/+tblish/+examples/peel_off_name_value_options.m index 17ed972a..759e3a18 100644 --- a/inst/+tblish/+examples/peel_off_name_value_options.m +++ b/inst/+tblish/+examples/peel_off_name_value_options.m @@ -63,11 +63,11 @@ # - if nargin < 3 || isempty (defaults); defaults = struct; endif + if (nargin < 3 || isempty (defaults)); defaults = struct; endif defaults = parse_defaults (defaults); opts = defaults; peeled_args = {}; - while numel (args) >= 2 && ischar (args{end-1}) && ismember (args{end-1}, known_opts) + while (numel (args) >= 2 && ischar (args{end-1}) && ismember (args{end-1}, known_opts)) peeled_args = [peeled_args args(end-1:end)]; opts.(args{end-1}) = args{end}; args(end-1:end) = []; @@ -76,12 +76,12 @@ endfunction function out = parse_defaults (defaults) - if isstruct (defaults) + if (isstruct (defaults)) out = struct; return endif - if iscell (defaults) - if size (defaults, 2) == 2 + if (iscell (defaults)) + if (size (defaults, 2) == 2) # Convert cellrec to name/value list defaults = defaults'; defaults = defaults(:)'; diff --git a/inst/+tblish/+examples/plot_pairs.m b/inst/+tblish/+examples/plot_pairs.m index d609f313..1a7a00a9 100644 --- a/inst/+tblish/+examples/plot_pairs.m +++ b/inst/+tblish/+examples/plot_pairs.m @@ -45,33 +45,33 @@ function out = plot_pairs (varargin) args = varargin; fig = []; - if isnumeric (args{1}) + if (isnumeric (args{1})) fig = args{1}; args(1) = []; endif data = args{1}; - if numel (args) > 1 + if (numel (args) > 1) plot_type = args{2}; else plot_type = 'scatter'; endif - if isstruct (data) + if (isstruct (data)) data = struct2table (data); endif - if ! istable (data) + if (! istable (data)) error ('plot_pairs: input data must be a table or struct'); endif t = data; - if isempty (fig) + if (isempty (fig)) fig = figure; endif vars = t.Properties.VariableNames; n_vars = numel (vars); for i = 1:n_vars for j = 1:n_vars - if i == j + if (i == j) # TODO: Figure out how to put the variable name in big text in this axes continue endif @@ -81,7 +81,7 @@ var_y = vars{j}; x = t.(var_x); y = t.(var_y); - switch plot_type + switch (plot_type) case "scatter" scatter (hax, x, y, 10); case "smooth" @@ -92,7 +92,7 @@ endfor endfor - if nargout > 0 + if (nargout > 0) out = fig; endif endfunction @@ -103,7 +103,7 @@ function smooth (hax, x, y, marker_sz) # port that. For now, just use a cubic. hold on p = polyfit (x, y, 3); - x_hat = unique(x); + x_hat = unique (x); p_y = polyval (p, x_hat); plot (hax, x_hat, p_y, "r"); hold off diff --git a/inst/+tblish/+examples/private/peelOffNameValueOptions.m b/inst/+tblish/+examples/private/peelOffNameValueOptions.m index 08fa18e7..34f766c0 100644 --- a/inst/+tblish/+examples/private/peelOffNameValueOptions.m +++ b/inst/+tblish/+examples/private/peelOffNameValueOptions.m @@ -19,7 +19,7 @@ # Peels off recognized name-value options from the end of an argument array. opts = struct; peeledArgs = {}; - while numel (args) >= 2 && ischar (args{end-1}) && ismember (args{end-1}, knownOpts) + while (numel (args) >= 2 && ischar (args{end-1}) && ismember (args{end-1}, knownOpts)) peeledArgs = [peeledArgs args(end-1:end)]; opts.(args{end-1}) = args{end}; args(end-1:end) = []; diff --git a/inst/+tblish/+examples/run_all_example_scripts.m b/inst/+tblish/+examples/run_all_example_scripts.m index d7768422..7bc4705c 100644 --- a/inst/+tblish/+examples/run_all_example_scripts.m +++ b/inst/+tblish/+examples/run_all_example_scripts.m @@ -1,4 +1,4 @@ -function run_all_example_scripts +function run_all_example_scripts () # Runs all example scripts in the inst/examples directory. # # This function is meant for use in BIST tests. It just ensures that all diff --git a/inst/+tblish/+internal/+chrono/+algo/binsearch.m b/inst/+tblish/+internal/+chrono/+algo/binsearch.m index 2f73f06c..d0c86093 100644 --- a/inst/+tblish/+internal/+chrono/+algo/binsearch.m +++ b/inst/+tblish/+internal/+chrono/+algo/binsearch.m @@ -21,10 +21,10 @@ # inserted; that is, the index of the first element larger than it, or one past # the end of the array if it is larger than all the elements in the haystack. - if !isvector (haystack) && !isempty (haystack) + if (! isvector (haystack) && !isempty (haystack)) error ('haystack must be a vector or empty'); endif - if !isequal (class (needles), class (haystack)) + if (! isequal (class (needles), class (haystack))) error ('needles and haystack must be same type; got %s and %s', ... class (needles), class (haystack)); endif @@ -34,8 +34,8 @@ 'uint8' 'uint16' 'uint32' 'uint64'}; is_numeric = ismember (class (needles), numeric_types); - if is_numeric - if iscomplex (needles) || iscomplex (haystack) + if (is_numeric) + if (iscomplex (needles) || iscomplex (haystack)) error ('Complex values are not supported'); endif loc = double (__tblish_time_binsearch__ (needles, haystack)); @@ -53,13 +53,13 @@ low = 1; high = numel (arr); found = false; - while low <= high + while (low <= high) mid = floor ((low + high) / 2); - if arr(mid) > val + if (arr(mid) > val) high = mid - 1; - elseif arr(mid) < val + elseif (arr(mid) < val) low = mid + 1; - elseif arr(mid) == val + elseif (arr(mid) == val) found = true; out(i) = mid; break; @@ -67,7 +67,7 @@ error('Total ordering violation: neither <, >, nor == was true for this value.'); endif endwhile - if !found + if (! found) out(i) = -1 * low; endif endfor diff --git a/inst/+tblish/+internal/+chrono/+tzinfo/PosixZoneRule.m b/inst/+tblish/+internal/+chrono/+tzinfo/PosixZoneRule.m index 224255e2..cec8e3eb 100644 --- a/inst/+tblish/+internal/+chrono/+tzinfo/PosixZoneRule.m +++ b/inst/+tblish/+internal/+chrono/+tzinfo/PosixZoneRule.m @@ -11,13 +11,14 @@ endproperties methods (Static) + function out = parseZoneRule (str) out = tblish.internal.chrono.algo.PosixZoneRule; - if !isrow (in) + if (! isrow (in)) error ('in must be charvec; got non-row char'); endif els = strsplit (in, ','); - if numel (els ~= 3) + if (numel (els != 3)) error ('Invalid POSIX time zone rule specification: ''%s''', in); endif out.local_timezone = els{1}; @@ -25,21 +26,23 @@ out.dst_end_rule = els{3}; tok = regexp (out.local_timezone, '^([A-Za-z]+)(\d+)([A-Za-z]+)$', 'tokens'); tok = tok{1}; - if numel (tok) ~= 3 + if (numel (tok) != 3) error ('Failed parsing POSIX zone name: ''%s''', out.local_timezone); endif out.std_name = tok{1}; out.gmt_offset_hours = str2double(tok{2}); out.dst_name = tok{3}; endfunction + endmethods methods + function this = PosixZoneRule(in) - if nargin == 0 + if (nargin == 0) return endif - if ischar (in) + if (ischar (in)) this = tblish.internal.chrono.tzinfo.PosixZoneRule.parseZoneRule(in); endif endfunction @@ -51,5 +54,7 @@ function out = localToGmtDatenum (this, dnums, isDst) error ('Unimplemented'); endfunction + endmethods + endclassdef diff --git a/inst/+tblish/+internal/+chrono/+tzinfo/TzDb.m b/inst/+tblish/+internal/+chrono/+tzinfo/TzDb.m index 6fa16f61..3adc258c 100644 --- a/inst/+tblish/+internal/+chrono/+tzinfo/TzDb.m +++ b/inst/+tblish/+internal/+chrono/+tzinfo/TzDb.m @@ -30,7 +30,7 @@ function out = instance () #INSTANCE Shared global instance of TzDb persistent value - if isempty (value) + if (isempty (value)) value = tblish.internal.chrono.tzinfo.TzDb; endif out = value; @@ -38,6 +38,7 @@ endmethods methods + function this = TzDb (path) #TZDB Construct a new TzDb object # @@ -46,8 +47,8 @@ # path (char) is the path to the tzinfo database directory. If omitted or # empty, it defaults to the default path ('/usr/share/zoneinfo' on Unix, # and an error on Windows). - if nargin < 1; path = []; endif - if isempty (path) + if (nargin < 1); path = []; endif + if (isempty (path)) this.path = tblish.internal.chrono.tzinfo.TzDb.defaultPath; else this.path = path; @@ -78,7 +79,7 @@ # Comments # Each of which contains a cellstr column vector. persistent data - if isempty (data) + if (isempty (data)) data = this.readZoneTab; endif out = data; @@ -89,10 +90,10 @@ # # out = definedZones (this) persistent value - if isempty (value) + if (isempty (value)) specialFiles = {'+VERSION', 'iso3166.tab', 'zone.tab', 'posixrules'}; files = tblish.internal.chrono.findFiles (this.path); - if ispc + if (ispc) files = strrep(files, '\', '/'); endif value = setdiff (files', specialFiles); @@ -114,7 +115,7 @@ # We prefer the version 2 stuff out = tblish.internal.chrono.tzinfo.TzInfo; - if isfield (s, 'section2') + if (isfield (s, 'section2')) defn_s = s.section2; defn_s.goingForwardPosixZone = s.goingForwardPosixZone; else @@ -127,6 +128,7 @@ endmethods methods (Access = private) + function out = readZoneTab (this) #READZONETAB Actually read and parse the zonetab file @@ -144,7 +146,7 @@ pattern = '^(\w+)\s+(\S+)\s+(\S+)\s*(.*)'; [match,tok] = regexp (lines, pattern, 'match', 'tokens'); tfMatch = ~cellfun ('isempty', match); - if !all (tfMatch) + if (! all (tfMatch)) ixBad = find (!tfMatch); error ('Failed parsing line in zone.tab file: "%s"', lines{ixBad(1)}); endif @@ -160,11 +162,11 @@ function out = readZoneFile (this, zoneId) #READZONEFILE Read and parse a zone definition file - if !ismember (zoneId, this.definedZones) + if (! ismember (zoneId, this.definedZones)) error ("Undefined time zone: '%s'", zoneId); endif zoneFile = [this.path '/' zoneId]; - if ~exist (zoneFile) + if (! exist (zoneFile)) error (["tzinfo time zone file for zone %s does not exist: %s\n" ... "This is probably an error in the tzinfo database files."], ... zoneId, zoneFile); @@ -184,8 +186,9 @@ endmethods methods (Static) + function out = defaultPath () - if ispc + if (ispc) # Use the zoneinfo database bundled with Tablicious, because Windows doesn't # supply one. this_dir = fileparts (mfilename ('fullpath')); @@ -194,6 +197,8 @@ out = '/usr/share/zoneinfo'; endif endfunction + endmethods + endclassdef diff --git a/inst/+tblish/+internal/+chrono/+tzinfo/TzInfo.m b/inst/+tblish/+internal/+chrono/+tzinfo/TzInfo.m index 76cfb864..6ee02243 100644 --- a/inst/+tblish/+internal/+chrono/+tzinfo/TzInfo.m +++ b/inst/+tblish/+internal/+chrono/+tzinfo/TzInfo.m @@ -18,7 +18,6 @@ classdef TzInfo #TZINFO Zone definition for a single time zone - # properties (Constant) utcZoneAliases = {'Etc/GMT' 'Etc/GMT+0' 'Etc/GMT-0' 'Etc/Greenwich' ... @@ -45,11 +44,12 @@ endproperties methods + function this = TzInfo(in) - if nargin == 0 - return; + if (nargin == 0) + return endif - if isstruct (in) + if (isstruct (in)) # Convert from TzDb's tzinfo struct s = in; this.id = s.zoneId; @@ -61,7 +61,7 @@ this.leapSecondTotals = s.leap_second_totals; this.isStd = s.is_std; this.isGmt = s.is_gmt; - if isfield (s, 'goingForwardPosixZone') + if (isfield (s, 'goingForwardPosixZone')) this.goingForwardPosixZone = s.goingForwardPosixZone; #this.goingForwardPosixZoneRule = tblish.internal.chrono.tzinfo.PosixZoneRule(... # this.goingForwardPosixZone); @@ -87,7 +87,7 @@ function display (this) #DISPLAY Custom display. in_name = inputname (1); - if !isempty (in_name) + if (! isempty (in_name)) fprintf ('%s =\n', in_name); endif disp (this); @@ -95,9 +95,9 @@ function display (this) function disp (this) #DISP Custom display. - if isempty (this) + if (isempty (this)) fprintf ('Empty %s %s\n', tblish.internal.chrono.size2str (size (this)), class (this)); - elseif isscalar (this) + elseif (isscalar (this)) fprintf ('TzInfo: %s\n', this.id); displayCommonInfo (this); else @@ -107,7 +107,7 @@ function disp (this) function prettyprint (this) #PRETTYPRINT Display this' data in human-readable format. - if !isscalar (this) + if (! isscalar (this)) fprintf ('%s: %s\n', class (this), tblish.internal.chrono.size2str (size (this))); return; endif @@ -129,7 +129,7 @@ function prettyprint (this) tti.gmtoff(i), char (gmtoffDur), tti.isdst(i), tti.abbrind(i), tti.abbr{i}); endfor fprintf ('leap times:\n'); - if isempty (this.leapTimes) + if (isempty (this.leapTimes)) fprintf (' \n'); else fprintf (' %12s %20s\n', 'time', 'leap seconds'); @@ -144,14 +144,14 @@ function prettyprint (this) fprintf (' %s\n', strjoin (num2cellstr (this.isStd), ' ')); fprintf ('is_gmt:\n'); fprintf (' %s\n', strjoin (num2cellstr (this.isGmt), ' ')); - if !isempty (this.goingForwardPosixZone) + if (! isempty (this.goingForwardPosixZone)) fprintf ('posix_zone:\n'); fprintf (' %s\n', this.goingForwardPosixZone); endif endfunction function out = localtimeToGmt (this, dnum) - if ismember (this.id, tblish.internal.chrono.tzinfo.TzInfo.utcZoneAliases) + if (ismember (this.id, tblish.internal.chrono.tzinfo.TzInfo.utcZoneAliases)) # Have to special-case this because it relies on POSIX zone rules, which # are not implemented yet offsets = zeros (size (dnum)); @@ -168,19 +168,19 @@ function prettyprint (this) for i_dnum = 1:numel(dnum) d = dnum(i_dnum); ix = find(this.transitionsLocalDatenum <= d, 1, "last"); - if !isempty(ix) + if (! isempty(ix)) tf(i_dnum) = true; loc(i_dnum) = ix; endif endfor - #[tf,loc] = tblish.internal.chrono.algo.binsearch (dnum, this.transitionsLocalDatenum); + # [tf,loc] = tblish.internal.chrono.algo.binsearch (dnum, this.transitionsLocalDatenum); ix = loc; tfOutOfRange = isnan(ix) | ix == numel (this.transitions); # In-range dates take their period's gmt offset offsets = NaN (size (dnum)); offsets(!tfOutOfRange) = this.ttinfos.gmtoffDatenum(this.timeTypes(ix(!tfOutOfRange))); # Out-of-range dates are handled by the POSIX look-ahead zone - if any (tfOutOfRange(:)) + if (any (tfOutOfRange(:))) # TODO: Implement this error ('POSIX zone rules are unimplemented'); endif @@ -189,7 +189,7 @@ function prettyprint (this) endfunction function out = gmtToLocaltime (this, dnum) - if ismember(this.id, tblish.internal.chrono.tzinfo.TzInfo.utcZoneAliases) + if (ismember(this.id, tblish.internal.chrono.tzinfo.TzInfo.utcZoneAliases)) # Have to special-case this because it relies on POSIX zone rules, which # are not implemented yet offsets = zeros( size (dnum)); @@ -202,7 +202,7 @@ function prettyprint (this) offsets = NaN (size (dnum)); offsets(!tfOutOfRange) = this.ttinfos.gmtoffDatenum(this.timeTypes(ix(!tfOutOfRange))); # Out-of-range dates are handled by the POSIX look-ehead zone - if any (tfOutOfRange(:)) + if (any (tfOutOfRange(:))) # TODO: Implement this error ('POSIX zone rules are unimplemented'); endif @@ -216,10 +216,10 @@ function prettyprint (this) function displayCommonInfo (this) #DISPLAYCOMMONINFO Info common to disp() and prettyprint() formatId = this.formatId; - if formatId == 0 + if (formatId == 0) formatId = '1'; endif - if ismember (this.formatId, {'2','3'}) + if (ismember (this.formatId, {'2','3'})) time_size = '64-bit'; else time_size = '32-bit'; @@ -229,7 +229,7 @@ function displayCommonInfo (this) numel (this.transitions), numel (this.ttinfos.gmtoff), numel (this.leapTimes)); fprintf (' %d is_stds, %d is_gmts\n', ... numel (this.isStd), numel (this.isGmt)); - if !isempty (this.goingForwardPosixZone) + if (! isempty (this.goingForwardPosixZone)) fprintf (' Forward-looking POSIX zone: %s\n', this.goingForwardPosixZone); endif endfunction diff --git a/inst/+tblish/+internal/+chrono/+tzinfo/TzZoneFile.m b/inst/+tblish/+internal/+chrono/+tzinfo/TzZoneFile.m index e3925614..b8d7eb09 100644 --- a/inst/+tblish/+internal/+chrono/+tzinfo/TzZoneFile.m +++ b/inst/+tblish/+internal/+chrono/+tzinfo/TzZoneFile.m @@ -36,10 +36,10 @@ methods function this = TzZoneFile (file) - if nargin == 0 + if (nargin == 0) return endif - if !isfile(file) + if (! isfile(file)) error('tblish.chrono:NoSuchFile', ... 'Cannot read TZ zone file: no such file: %s', file); endif @@ -49,7 +49,7 @@ function out = readZoneFile (this) #READZONEFILE Read and parse a zone definition file - if ~exist (this.file) + if (! exist (this.file)) # This shouldn't happen unless the file has been moved on disk since # object construction. error('No such file: %s', this.file); @@ -63,16 +63,16 @@ out.section1 = section1; # Version 2 stuff - if ismember (section1.header.format_id, {'2','3'}) + if (ismember (section1.header.format_id, {'2','3'})) # A whole nother header/data, except using 8-byte transition/leap times ix = ix + n_bytes_read; # Scan for the magic cookie to double-check our parsing. magic_ixs = strfind (char (data(ix:end)), 'TZif'); - if isempty (magic_ixs) + if (isempty (magic_ixs)) # No second section found else # Advance to where we found the magic cookie - if magic_ixs(1) ~= 1 + if (magic_ixs(1) != 1) warning (['Unexpected extra data at end of section in tzinfo file for %s.\n' ... 'Possible bug in chrono''s parsing code.'], zoneId); endif diff --git a/inst/+tblish/+internal/+chrono/+tzinfo/WindowsIanaZoneConverter.m b/inst/+tblish/+internal/+chrono/+tzinfo/WindowsIanaZoneConverter.m index 95fef716..6c88051b 100644 --- a/inst/+tblish/+internal/+chrono/+tzinfo/WindowsIanaZoneConverter.m +++ b/inst/+tblish/+internal/+chrono/+tzinfo/WindowsIanaZoneConverter.m @@ -23,16 +23,16 @@ function out = windows2iana (this, winZoneId) map = getZoneMap (this); ix = find (strcmp (winZoneId, map.Windows)); - if isempty (ix) + if (isempty (ix)) error ('Unrecognized Windows time zone ID: ''%s''', winZoneId); endif territories = map.Territory(ix); ianas = map.Iana(ix); - if isscalar (ix) + if (isscalar (ix)) out = ianas{1}; else [tf,loc] = ismember ('001', territories); - if !tf + if (! tf) out = ianas{1}; warning (['No "001" territory found for Windows time zone ''%s'' in map file. ' ... 'Guessing IANA zone randomly as ''%s''.'], ... @@ -46,7 +46,7 @@ function out = iana2windows (this, ianaZoneId) map = getZoneMap (this); [tf,loc] = ismember (ianaZoneId, map.Iana); - if !tf + if (! tf) error ('Unrecognized IANA time zone ID: ''%s''', ianaZoneId); endif out = map.Windows{loc}; @@ -54,7 +54,7 @@ function out = getZoneMap (this) persistent cache - if isempty (cache) + if (isempty (cache)) cache = readWindowsZonesFile (this); endif out = cache; @@ -73,5 +73,6 @@ out.Iana = tok(:,3); endfunction endmethods + endclassdef diff --git a/inst/+tblish/+internal/+chrono/+tzinfo/ZoneFileSectionParser.m b/inst/+tblish/+internal/+chrono/+tzinfo/ZoneFileSectionParser.m index 6c46a497..27f8702e 100644 --- a/inst/+tblish/+internal/+chrono/+tzinfo/ZoneFileSectionParser.m +++ b/inst/+tblish/+internal/+chrono/+tzinfo/ZoneFileSectionParser.m @@ -29,29 +29,30 @@ endproperties methods + function out = take_byte (this, n) - if nargin < 2; n = 1; end + if (nargin < 2); n = 1; end n = double (n); out = this.data(this.ix:this.ix + n - 1); this.ix = this.ix + n; endfunction function out = take_int (this, n) - if nargin < 2; n = 1; end + if (nargin < 2); n = 1; end n = double (n); out = this.get_int (this.data(this.ix:this.ix + (4*n) - 1)); this.ix = this.ix + 4*n; endfunction function out = take_int64 (this, n) - if nargin < 2; n = 1; end + if (nargin < 2); n = 1; end n = double (n); out = this.get_int64 (this.data(this.ix:this.ix+(8*n)-1)); this.ix = this.ix + 8*n; endfunction function out = take_timeval (this, n) - if this.sectionFormat == 1 + if (this.sectionFormat == 1) out = this.take_int (n); else out = this.take_int64 (n); @@ -68,7 +69,7 @@ function out = get_null_terminated_string (this, my_bytes) my_ix = 1; - while my_bytes(my_ix) ~= 0 + while (my_bytes(my_ix) != 0) my_ix = my_ix + 1; endwhile out = char (my_bytes(1:my_ix - 1)); @@ -113,10 +114,10 @@ # no length indicator for them, so we have to scan for the null after the # last string. abbrs = {}; - if !isempty (ttinfos.abbrind) + if (! isempty (ttinfos.abbrind)) last_abbrind = max (ttinfos.abbrind); ix_end = this.ix + double (last_abbrind); - while this.data(ix_end) ~= 0 + while (this.data(ix_end) != 0) ix_end = ix_end + 1; endwhile abbr_section = this.data(this.ix:ix_end); @@ -127,7 +128,7 @@ this.ix = ix_end + 1; endif ttinfos.abbr = abbrs; - if this.sectionFormat == 1 + if (this.sectionFormat == 1) leap_times = repmat (uint32 (0), [h.n_leap 1]); else leap_times = repmat (uint64 (0), [h.n_leap 1]); @@ -150,6 +151,7 @@ out.is_gmt = is_gmt; nBytesRead = this.ix - 1; endfunction + endmethods endclassdef diff --git a/inst/+tblish/+internal/+chrono/detect_system_timezone.m b/inst/+tblish/+internal/+chrono/detect_system_timezone.m index 305ed651..1f14f061 100644 --- a/inst/+tblish/+internal/+chrono/detect_system_timezone.m +++ b/inst/+tblish/+internal/+chrono/detect_system_timezone.m @@ -20,7 +20,7 @@ try out = do_detection (); tzdb = tblish.internal.chrono.tzinfo.TzDb; - if !ismember (out, tzdb.definedZones) + if (! ismember (out, tzdb.definedZones)) warning ('System time zone ''%s'' is not defined in the tzinfo database.', ... out); endif @@ -39,17 +39,17 @@ # Let TZ env var take precedence tz_env = getenv ('TZ'); - if !isempty (tz_env) + if (! isempty (tz_env)) out = tz_env; endif # Get actual system default, using OS-specific mechanisms - if isempty (out) && isfile ('/etc/localtime') + if (isempty (out) && isfile ('/etc/localtime')) # This exists on macOS and RHEL/CentOS 7/some Fedora # By convention, when it's a symlink, it points into a file whose path is the same # as the IANA time zone identifier. [target,err,msg] = readlink ('/etc/localtime'); - if err + if (err) # It's not a symlink. And we can't pull the zone name out of the file contents # because zone info files do not store their names internally. (LOL.) # Ignore and fall back to another detection method @@ -57,28 +57,28 @@ out = regexprep (target, '.*/zoneinfo/', ''); endif endif - if isempty (out) && exist ('/etc/timezone') + if (isempty (out) && exist ('/etc/timezone')) # This exists on Debian out = strtrim (tblish.internal.chrono.slurpTextFile ('/etc/timezone')); endif - if isempty (out) && ispc + if (isempty (out) && ispc) # Newer Windows can do it with PowerShell win_zone = detect_timezone_using_powershell; - if !isempty (win_zone) + if (! isempty (win_zone)) converter = tblish.internal.chrono.tzinfo.WindowsIanaZoneConverter; out = converter.windows2iana (win_zone); endif endif - if isempty (out) + if (isempty (out)) # Fall back to Java if nothing else worked - if !usejava ('jvm') + if (! usejava ('jvm')) warning ('tablicious:TimeZoneDetectionFailure', 'Detecting time zone on this OS requires Java, which is not available in this Octave build.'); else zone = javaMethod ('getDefault', 'java.util.TimeZone'); out = char (zone.getID()); endif endif - if isempty (out) + if (isempty (out)) warning ('tablicious:TimeZoneDetectionFailure', 'Warning: Failed detecting system time zone.'); endif endfunction @@ -87,12 +87,12 @@ # This only works on Windows Vista or newer. Windows 7 and older lack the # Get-TimeZone command. [status, txt] = system ('powershell -Command Get-TimeZone'); - if status ~= 0 + if (status != 0) out = []; return endif info = parse_powershell_get_timezone_output (txt); - if isempty (info) + if (isempty (info)) out = []; return endif @@ -103,7 +103,7 @@ str = strrep (str, "\r\n", "\n"); [match,tok] = regexp (str, '^(\w+)\s*:\s*(\S.*?)(?=\n|$)', ... 'match', 'tokens', 'lineanchors'); - if isempty (match) + if (isempty (match)) out = []; else tok = cat(1, tok{:}); diff --git a/inst/+tblish/+internal/+chrono/findFiles.m b/inst/+tblish/+internal/+chrono/findFiles.m index 13a32bd4..4db6222d 100644 --- a/inst/+tblish/+internal/+chrono/findFiles.m +++ b/inst/+tblish/+internal/+chrono/findFiles.m @@ -26,8 +26,7 @@ d = mydir (dirPath); for i = 1:numel (d) f = d(i); - if f.isdir - # Can't use spaces here or syntax error happens + if (f.isdir) found = [found findFilesStep(fullfile (dirPath, f.name), ... fullfile(pathPrefix, f.name))]; else diff --git a/inst/+tblish/+internal/+chrono/format_dispstr_array.m b/inst/+tblish/+internal/+chrono/format_dispstr_array.m index 16843b47..9c398fff 100644 --- a/inst/+tblish/+internal/+chrono/format_dispstr_array.m +++ b/inst/+tblish/+internal/+chrono/format_dispstr_array.m @@ -19,7 +19,7 @@ function out = format_dispstr_array (strs) #FORMAT_DISPSTR_ARRAY Format an array of strings as a matrix display - if ismatrix (strs) + if (ismatrix (strs)) out = prettyprint_matrix (strs); else sz = size (strs); @@ -40,14 +40,14 @@ endfor out = strjoin (chunks, '\n'); endif - if nargout == 0 + if (nargout == 0) disp (out); clear out; endif endfunction function out = prettyprint_matrix (strs) - if !ismatrix (strs) + if (! ismatrix (strs)) error ('Input must be matrix; got %d-D', ndims (strs)); endif lens = cellfun ('prodofsize', strs); diff --git a/inst/+tblish/+internal/+chrono/mustBeIntVal.m b/inst/+tblish/+internal/+chrono/mustBeIntVal.m index 8ca4ce40..893cf976 100644 --- a/inst/+tblish/+internal/+chrono/mustBeIntVal.m +++ b/inst/+tblish/+internal/+chrono/mustBeIntVal.m @@ -17,7 +17,7 @@ ## . function mustBeIntVal(x) - if any(any(fix(x) ~= x)) - error('Input %s must be an integer value', inputname(1)); + if (any (any (fix(x) != x))) + error ('Input %s must be an integer value', inputname(1)); endif endfunction diff --git a/inst/+tblish/+internal/+chrono/mustBeScalar.m b/inst/+tblish/+internal/+chrono/mustBeScalar.m index b1fc26f5..6843e9ef 100644 --- a/inst/+tblish/+internal/+chrono/mustBeScalar.m +++ b/inst/+tblish/+internal/+chrono/mustBeScalar.m @@ -17,7 +17,7 @@ ## . function mustBeScalar(x) - if !isscalar(x) - error('Input %s must be scalar', inputname(1)); + if (! isscalar(x)) + error ('Input %s must be scalar', inputname(1)); endif endfunction diff --git a/inst/+tblish/+internal/+chrono/mycombvec.m b/inst/+tblish/+internal/+chrono/mycombvec.m index e2949641..b3cde042 100644 --- a/inst/+tblish/+internal/+chrono/mycombvec.m +++ b/inst/+tblish/+internal/+chrono/mycombvec.m @@ -20,10 +20,10 @@ #MYCOMBVEC All combinations of values from vectors # # This is similar to Matlab's combvec, but has a different signature. - if !iscell (vecs) + if (! iscell (vecs)) error ('Input vecs must be cell'); endif - switch numel (vecs) + switch (numel (vecs)) case 0 error ('Must supply at least one input vector'); case 1 diff --git a/inst/+tblish/+internal/+chrono/prefillNewSizeForSubsasgn.m b/inst/+tblish/+internal/+chrono/prefillNewSizeForSubsasgn.m index 8a95f039..d6851b10 100644 --- a/inst/+tblish/+internal/+chrono/prefillNewSizeForSubsasgn.m +++ b/inst/+tblish/+internal/+chrono/prefillNewSizeForSubsasgn.m @@ -17,31 +17,31 @@ ## . function out = prefillNewSizeForSubsasgn(x, ixRef, fillVal) - sz = size(x); - if isequal(ixRef, ':') + sz = size (x); + if (isequal (ixRef, ':')) out = x; - elseif isscalar(ixRef) + elseif (isscalar (ixRef)) ix = ixRef{1}; out = x; - if max(ix) > numel(x) - if !isvector(x) - error('Invalid resizing operation using out-of-bounds linear indexing on a non-vector input'); + if (max (ix) > numel (x)) + if (! isvector (x)) + error ('Invalid resizing operation using out-of-bounds linear indexing on a non-vector input'); endif out(max(ix)) = fillVal; out(numel(x)+1:end) = fillVal; endif else ixs = ixRef; - newSz = NaN([1 ndims(x)]); - for i = 1:numel(ixs) - newSz = max(size(x, i), max(ixs{i})); + newSz = NaN ([1 ndims(x)]); + for i = 1:numel (ixs) + newSz = max (size (x, i), max (ixs{i})); endfor - if isequal(sz, newSz) + if (isequal (sz, newSz)) out = x; else - out = NaN(newSz); - oldRange = cell(1, ndims(x)); - for i = 1:numel(oldRange) + out = NaN (newSz); + oldRange = cell (1, ndims (x)); + for i = 1:numel (oldRange) oldRange{i} = 1:size(x,i); endfor out(oldRange{:}) = x; diff --git a/inst/+tblish/+internal/+chrono/prettyprint_array.m b/inst/+tblish/+internal/+chrono/prettyprint_array.m index 2c00e598..36abba83 100644 --- a/inst/+tblish/+internal/+chrono/prettyprint_array.m +++ b/inst/+tblish/+internal/+chrono/prettyprint_array.m @@ -44,23 +44,23 @@ endfor out = strjoin (chunks, '\n'); endif -if nargout == 0 +if (nargout == 0) disp (out); clear out; endif endfunction function out = prettyprint_matrix (strs) -if !ismatrix (strs) +if (! ismatrix (strs)) error ('Input must be matrix; got %d-D', ndims (strs)); endif lens = cellfun ('prodofsize', strs); widths = max (lens); formats = tblish.internal.chrono.sprintfv ('%%%ds', widths); -format = strjoin (formats, ' '); +myFormat = strjoin (formats, ' '); lines = cell (size (strs,1), 1); for i = 1:size (strs, 1) - lines{i} = sprintf (format, strs{i,:}); + lines{i} = sprintf (myFormat, strs{i,:}); endfor out = strjoin (lines, '\n'); endfunction diff --git a/inst/+tblish/+internal/+chrono/scalarexpand.m b/inst/+tblish/+internal/+chrono/scalarexpand.m index 90bdb4f2..94c961c1 100644 --- a/inst/+tblish/+internal/+chrono/scalarexpand.m +++ b/inst/+tblish/+internal/+chrono/scalarexpand.m @@ -21,12 +21,12 @@ sz = []; for i = 1:nargin - if !isscalar (varargin{i}) + if (! isscalar (varargin{i})) sz_i = size (varargin{i}); - if isempty (sz) + if (isempty (sz)) sz = sz_i; else - if !isequal (sz, sz_i) + if (! isequal (sz, sz_i)) error ('Matrix dimensions must agree (%s vs %s)',... tblish.internal.chrono.size2str (sz), tblish.internal.chrono.size2str (sz_i)) endif @@ -36,12 +36,12 @@ varargout = varargin; - if isempty (sz) + if (isempty (sz)) return endif for i = 1:nargin - if isscalar (varargin{i}) + if (isscalar (varargin{i})) varargout{i} = repmat (varargin{i}, sz); endif endfor diff --git a/inst/+tblish/+internal/+chrono/slurpBinaryFile.m b/inst/+tblish/+internal/+chrono/slurpBinaryFile.m index 59037605..c59d8c0b 100644 --- a/inst/+tblish/+internal/+chrono/slurpBinaryFile.m +++ b/inst/+tblish/+internal/+chrono/slurpBinaryFile.m @@ -18,7 +18,7 @@ function out = slurpBinaryFile (file) [fid,msg] = fopen (file, 'r'); - if fid == -1 + if (fid == -1) error ('Could not open file %s: %s', file, msg); endif cleanup.fid = onCleanup (@() fclose (fid)); diff --git a/inst/+tblish/+internal/+chrono/slurpTextFile.m b/inst/+tblish/+internal/+chrono/slurpTextFile.m index 970f5420..9c44e2cd 100644 --- a/inst/+tblish/+internal/+chrono/slurpTextFile.m +++ b/inst/+tblish/+internal/+chrono/slurpTextFile.m @@ -19,7 +19,7 @@ function out = slurpTextFile (file) #SLURPTEXTFILE Read a file's contents as text. [fid, msg] = fopen (file, 'r'); - if fid == -1 + if (fid == -1) error ('Could not open file %s: %s', file, msg); endif cleanup.fid = onCleanup (@() fclose (fid)); diff --git a/inst/+tblish/+internal/+chrono/sprintfv.m b/inst/+tblish/+internal/+chrono/sprintfv.m index 637e7a16..5eb3699a 100644 --- a/inst/+tblish/+internal/+chrono/sprintfv.m +++ b/inst/+tblish/+internal/+chrono/sprintfv.m @@ -16,7 +16,7 @@ ## along with Octave; see the file COPYING. If not, see ## . -function out = sprintfv (format, varargin) +function out = sprintfv (fmt, varargin) #SPRINTFV "Vectorized" sprintf # # out = sprintfv (format, varargin) @@ -32,14 +32,14 @@ args = varargin; sz = []; for i = 1:numel (args) - if ischar (args{i}) + if (ischar (args{i})) args{i} = { args{i} }; %#ok endif - if !isscalar (args{i}) - if isempty (sz) + if (! isscalar (args{i})) + if (isempty (sz)) sz = size (args{i}); else - if !isequal (sz, size (args{i})) + if (! isequal (sz, size (args{i}))) error ('Inconsistent dimensions in inputs'); endif endif @@ -53,18 +53,18 @@ for i = 1:numel (out) theseArgs = cell (size (args)); for iArg = 1:numel (args) - if isscalar (args{iArg}) + if (isscalar (args{iArg})) ix_i = 1; else ix_i = i; endif - if iscell (args{iArg}) + if (iscell (args{iArg})) theseArgs{iArg} = args{iArg}{ix_i}; else theseArgs{iArg} = args{iArg}(ix_i); endif endfor - out{i} = sprintf (format, theseArgs{:}); + out{i} = sprintf (fofmtrmat, theseArgs{:}); endfor endfunction diff --git a/inst/+tblish/+internal/+table/blankTable.m b/inst/+tblish/+internal/+table/blankTable.m index 1da6ec40..e0016a99 100644 --- a/inst/+tblish/+internal/+table/blankTable.m +++ b/inst/+tblish/+internal/+table/blankTable.m @@ -36,30 +36,30 @@ ## Returns a table array. function out = blankTable (sz, varTypes, varNames, fillStyle) -if nargin < 3 || isempty(varNames); varNames = {}; endif -if nargin < 4 || isempty (fillStyle); fillStyle = 'outer'; endif +if (nargin < 3 || isempty(varNames)); varNames = {}; endif +if (nargin < 4 || isempty (fillStyle)); fillStyle = 'outer'; endif varTypes = cellstr (varTypes); varNames = cellstr (varNames); mustBeMember (fillStyle, {'outer', 'ctor'}) -if !isequal (size (sz), [1 2]) +if (! isequal (size (sz), [1 2])) error ('sz must be exactly size 1-by-2; was size %s', size2str (size (sz))) endif doCtorStyle = isequal (fillStyle, 'ctor'); [nRows, nVars] = deal (sz(1), sz(2)); -if isempty (varNames) +if (isempty (varNames)) varNames = tblish.internal.table.defaultVarNames (nVars); endif varVals = cell (1, nVars); for i = 1:nVars - if doCtorStyle + if (doCtorStyle) proto = tblish.internal.table.fillValForTypeCtorStyle (varTypes{i}); else proto = tblish.internal.table.fillValForType (varTypes{i}); endif - if nRows == 1 + if (nRows == 1) varVal = proto; else varVal = repmat (proto, [nRows 1]); diff --git a/inst/+tblish/+internal/+table/fillValForType.m b/inst/+tblish/+internal/+table/fillValForType.m index 258c763d..a951009c 100644 --- a/inst/+tblish/+internal/+table/fillValForType.m +++ b/inst/+tblish/+internal/+table/fillValForType.m @@ -53,7 +53,7 @@ # * The regular array expansion fill value is not what we want for a fill value # for use in tables. persistent specialCases unsupportedTypes -if isempty (specialCases) +if (isempty (specialCases)) dummyTable = table (NaN); dummyTable = dummyTable(:,[]); specialCases = { @@ -68,20 +68,20 @@ unsupportedTypes = {'table'}; endif -if isstring (typeName) +if (isstring (typeName)) mustBeScalar (typeName); typeName = char (typeName); endif -if isempty (typeName) +if (isempty (typeName)) error ('typeName may not be an empty string') endif -if ismember (typeName, unsupportedTypes) +if (ismember (typeName, unsupportedTypes)) error ('type is not supported for table fill value detection: %s', typeName) endif # Special cases [tf,loc] = ismember (typeName, specialCases(:,1)); -if tf +if (tf) out = specialCases{loc,2}; return endif diff --git a/inst/+tblish/+internal/+table/fillValForTypeCtorStyle.m b/inst/+tblish/+internal/+table/fillValForTypeCtorStyle.m index 118c85d2..27cd383a 100644 --- a/inst/+tblish/+internal/+table/fillValForTypeCtorStyle.m +++ b/inst/+tblish/+internal/+table/fillValForTypeCtorStyle.m @@ -38,7 +38,7 @@ function out = fillValForTypeCtorStyle (typeName) persistent ctorSpecialCases specialCases intTypes unsupportedTypes -if isempty (ctorSpecialCases) +if (isempty (ctorSpecialCases)) dummyTable = table (NaN); dummyTable = dummyTable(:,[]); # ctorSpecialCases are those for which the preallocation constructor defines a fill @@ -71,28 +71,28 @@ unsupportedTypes = {}; endif -if isstring (typeName) +if (isstring (typeName)) mustBeScalar (typeName); typeName = char (typeName); endif -if isempty (typeName) +if (isempty (typeName)) error ('typeName may not be an empty string') endif -if ismember (typeName, unsupportedTypes) +if (ismember (typeName, unsupportedTypes)) error ('type is not supported for table fill value detection: %s', typeName) endif # Special cases -if ismember (typeName, intTypes) +if (ismember (typeName, intTypes)) out = zeros ([1 1], typeName); end [tf,loc] = ismember (typeName, ctorSpecialCases(:,1)); -if tf +if (tf) out = ctorSpecialCases{loc,2}; return endif [tf,loc] = ismember (typeName, specialCases(:,1)); -if tf +if (tf) out = specialCases{loc,2}; return endif diff --git a/inst/+tblish/+internal/+table/fillValForTypeGeneric.m b/inst/+tblish/+internal/+table/fillValForTypeGeneric.m index 72d91525..fa37c47c 100644 --- a/inst/+tblish/+internal/+table/fillValForTypeGeneric.m +++ b/inst/+tblish/+internal/+table/fillValForTypeGeneric.m @@ -32,7 +32,7 @@ error (["could not detect table fill value for type '%s': error when calling " ... "zero-arg constructor: %s"], typeName, err.message) end -if ~isscalar (protoVal) +if (! isscalar (protoVal)) error (["could not detect table fill value for type '%s': zero-arg constructor " ... "returned a non-scalar value: size was %s"], typeName, size2str (size (protoVal))) endif diff --git a/inst/+tblish/+internal/+table/fillValForVal.m b/inst/+tblish/+internal/+table/fillValForVal.m index f39f18a0..0e30b552 100644 --- a/inst/+tblish/+internal/+table/fillValForVal.m +++ b/inst/+tblish/+internal/+table/fillValForVal.m @@ -42,30 +42,30 @@ function out = fillValForVal (x) nCols = size (x, 2); - if isnumeric (x) - if isa (x, 'double') + if (isnumeric (x)) + if (isa (x, 'double')) out = NaN (1, nCols); - elseif isa (x, 'single') + elseif (isa (x, 'single')) out = single (NaN (1, nCols)); - elseif isinteger (x) + elseif (isinteger (x)) out = zeros (1, nCols, class (x)); else error ('table: value was numeric but not single, double, or integer: %s', ... class (x)); endif - elseif iscell (x) - if iscellstr (x) + elseif (iscell (x)) + if (iscellstr (x)) # This is an exception to the "check the type, not its values" rule. out = repmat ({''}, 1, nCols); else out = repmat ({[]}, 1, nCols); endif - elseif isa (x, 'datetime') + elseif (isa (x, 'datetime')) out = NaT (1, nCols); - elseif isa (x, 'string') + elseif (isa (x, 'string')) out = NaS (1, nCols); - elseif isa (x, 'table') - if hasrownames (x) + elseif (isa (x, 'table')) + if (hasrownames (x)) error (['table: cannot construct outer fill values for table-valued ' ... 'variables that have row names']); endif @@ -75,11 +75,11 @@ endfor varNames = x.Properties.VariableNames; out = table (varVals{:}, 'VariableNames', x.Properties.VariableNames); - elseif isa (x, 'categorical') + elseif (isa (x, 'categorical')) out = NaC (1, nCols); else # General case: Fall back to using array-expansion fill value - if isempty (x) + if (isempty (x)) # Assume the 0-arg constructor works x0 = feval (class (x)); else diff --git a/inst/+tblish/+internal/+table/gen_colvecfun.m b/inst/+tblish/+internal/+table/gen_colvecfun.m index 330ec2f5..52bcdbc5 100644 --- a/inst/+tblish/+internal/+table/gen_colvecfun.m +++ b/inst/+tblish/+internal/+table/gen_colvecfun.m @@ -15,11 +15,11 @@ function gen_colvecfun (maxdepth) #GEN_COLVECFUN Meta-function to generate the colvecfun implementation - if nargin < 2 || isempty (maxdepth); maxdepth = 20; endif + if (nargin < 2 || isempty (maxdepth)); maxdepth = 20; endif out_file = 'colvecfun_impl.txt'; fid = fopen (out_file, 'w'); - function p(fmt, varargin) + function p (fmt, varargin) fprintf(fid, [fmt '\n'], varargin{:}); endfunction diff --git a/inst/+tblish/+internal/+table/jndx2kndxs.m b/inst/+tblish/+internal/+table/jndx2kndxs.m index 282ada04..24565ba5 100644 --- a/inst/+tblish/+internal/+table/jndx2kndxs.m +++ b/inst/+tblish/+internal/+table/jndx2kndxs.m @@ -1,4 +1,6 @@ -function out = jndx2kndxs(jndx) +function out = jndx2kndxs (jndx) + # Convert the `[jndx = ...]` output of ismember etc. to a cell vector of indexes + # for each distinct jndx value. n = max (jndx); out = cell (n, 1); for i = 1:n diff --git a/inst/+tblish/+internal/+table/matchrows.m b/inst/+tblish/+internal/+table/matchrows.m index f0f864f8..1de50068 100644 --- a/inst/+tblish/+internal/+table/matchrows.m +++ b/inst/+tblish/+internal/+table/matchrows.m @@ -42,11 +42,11 @@ # values (as long as output ordering for partial-NaN rows is not significant), # at which point a pair of ismember() calls might work. - if !ismatrix (A) - error ('matchrows: input A must be a matrix; got a %s', size2str ( size (A))); + if (! ismatrix (A)) + error ('matchrows: input A must be a matrix; got a %s', size2str (size (A))); endif - if !ismatrix (B) - error ('matchrows: input B must be a matrix; got a %s', size2str ( size (B))); + if (! ismatrix (B)) + error ('matchrows: input B must be a matrix; got a %s', size2str (size (B))); endif # Two-way ismember will often be faster, but it's not well tested yet @@ -122,7 +122,7 @@ for iB = 1:nRowsB # all(... == ...) is much faster than isequal(). Use that. #if isequal (A(iA,:), B(iB,:)) - if all (A(iA,:) == B(iB,:)) + if (all (A(iA,:) == B(iB,:))) nMatches = nMatches + 1; ixs(nMatches,:) = [iA iB]; tfMatchedA(iA) = true; diff --git a/inst/+tblish/+internal/+table/mx_summary.m b/inst/+tblish/+internal/+table/mx_summary.m index f8fdce9d..cc8c7ab0 100644 --- a/inst/+tblish/+internal/+table/mx_summary.m +++ b/inst/+tblish/+internal/+table/mx_summary.m @@ -26,15 +26,15 @@ out.Size = size (x); out.Type = class (x); - if isnumeric (x) + if (isnumeric (x)) out = mx_summary_numeric (x, out); - elseif isa (x, 'datetime') + elseif (isa (x, 'datetime')) out = mx_summary_datetime (x, out); - elseif isa (x, 'duration') + elseif (isa (x, 'duration')) out = mx_summary_numeric (x, out); % Works because duration supports isnan() - elseif islogical (x) + elseif (islogical (x)) out = mx_summary_logical (x, out); - elseif isa (x, 'categorical') + elseif (isa (x, 'categorical')) out = mx_summary_categorical (x, out); else % nop: we've already got Size and Type; that's all that is supported diff --git a/inst/+tblish/+internal/+table/vartype_filter.m b/inst/+tblish/+internal/+table/vartype_filter.m index 08fbd24a..db2ce23d 100644 --- a/inst/+tblish/+internal/+table/vartype_filter.m +++ b/inst/+tblish/+internal/+table/vartype_filter.m @@ -21,18 +21,20 @@ endproperties methods - function this = vartype_filter(type) - mustBeCharvec(type); + + function this = vartype_filter (type) + mustBeCharvec (type); this.type = type; endfunction function out = matches (this, variable_value) - if isequal (this.type, 'cellstr') + if (isequal (this.type, 'cellstr')) out = iscellstr (variable_value); else out = isa (variable_value, this.type); endif endfunction + endmethods endclassdef diff --git a/inst/+tblish/+internal/cmp_versions.m b/inst/+tblish/+internal/cmp_versions.m index 95532569..d1be2c5d 100644 --- a/inst/+tblish/+internal/cmp_versions.m +++ b/inst/+tblish/+internal/cmp_versions.m @@ -1,18 +1,18 @@ -function out = cmp_versions(a, b) - av = parse_version(a); - bv = parse_version(b); - if numel(av) < numel(bv) - av(end+1:numel(bv)) = 0; +function out = cmp_versions (a, b) + av = parse_version (a); + bv = parse_version (b); + if (numel (av) < numel (bv)) + av(end+1:numel (bv)) = 0; endif - if numel(bv) < numel(av) - bv(end+1:numel(av)) = 0; + if (numel (bv) < numel (av)) + bv(end+1:numel (av)) = 0; endif - for i = 1:numel(av) - if av(i) < bv(i) + for i = 1:numel (av) + if (av(i) < bv(i)) out = -1; return endif - if av(i) > bv(i) + if (av(i) > bv(i)) out = 1; return endif @@ -20,11 +20,11 @@ out = 0; endfunction -function out = parse_version(v) - cmps = strsplit(v, '.'); - out = cellfun(@str2double, cmps); +function out = parse_version (v) + cmps = strsplit (v, '.'); + out = cellfun (@str2double, cmps); for i = 1:numel(out) - if isnan(out(i)) + if (isnan (out(i))) error ('Failed parsing version ''%s'': Got NaN in element %d', i); endif endfor diff --git a/inst/+tblish/+internal/dataset.m b/inst/+tblish/+internal/dataset.m index a1379150..bd7eddc6 100644 --- a/inst/+tblish/+internal/dataset.m +++ b/inst/+tblish/+internal/dataset.m @@ -134,7 +134,7 @@ methods (Static) function out = lookup (name) - if ! ismember (name, tblish.internal.dataset.included_datasets) + if (! ismember (name, tblish.internal.dataset.included_datasets)) error ("No defined dataset with name '%s'", name); endif class_name = ["tblish.internal.datasets." name]; @@ -160,14 +160,14 @@ function regenerate_all_datasets () # # This method must return a scalar struct whose fields are # the variables defined in this dataset. - error("dataset.load is abstract. Subclass %s must implement it, but it does not.", ... + error ("dataset.load is abstract. Subclass %s must implement it, but it does not.", ... class (this)); endfunction function out = description_texi (this) #DESCRIPTION_TEXI Get the Texinfo description for this dataset description_file = fullfile (this.class_dir, "description.texi"); - if ! isfile (description_file) + if (! isfile (description_file)) out = ""; return endif @@ -178,15 +178,15 @@ function regenerate_all_datasets () example_scripts_dir = fullfile (octave_namespace_dir, "+examples", ... "+internal", "+datasets"); # Include example scripts - while true + while (true) [ix_start, ix_end, tok] = regexp (texi, '@INCLUDE_DATASET_EXAMPLE_SCRIPT\{(.*?)\}', ... "start", "end", "tokens"); - if isempty (ix_start) + if (isempty (ix_start)) break endif script_file_base = tok{1}{1}; script_file = fullfile (example_scripts_dir, script_file_base); - if ! isfile (script_file) + if (! isfile (script_file)) error ("dataset.description_texi: File not found: %s", script_file); endif script = fileread (script_file); @@ -230,7 +230,7 @@ function cache_dataset (this) function out = cache_file_path (this) #CACHE_FILE_PATH Path to the local cache file, for classes that use caching - if ispc + if (ispc) error (["tblish.internal.dataset.cache_file_path: this is not " ... "implemented for Windows yet. Sorry."]); else diff --git a/inst/+tblish/+internal/generate_datasets_list.m b/inst/+tblish/+internal/generate_datasets_list.m index 7ed2711e..86afd5a9 100644 --- a/inst/+tblish/+internal/generate_datasets_list.m +++ b/inst/+tblish/+internal/generate_datasets_list.m @@ -24,11 +24,11 @@ function generate_datasets_list () names = tblish.internal.dataset.included_datasets; txt = {}; - function p(fmt, varargin) - txt{end+1} = sprintf(fmt, varargin{:}); + function p (fmt, varargin) + txt{end+1} = sprintf (fmt, varargin{:}); endfunction - for i_dataset = 1:numel(names) + for i_dataset = 1:numel (names) name = names{i_dataset}; dset = tblish.internal.dataset.lookup (name); @@ -74,7 +74,7 @@ function p(fmt, varargin) out_txt = strrep (in_txt, '@DATASET_LIST_GOES_HERE@', txt); [fid, msg] = fopen (dataset_m_file, "w"); - fprintf(fid, "%s", out_txt); + fprintf (fid, "%s", out_txt); fclose (fid); fprintf ("Regenerated %s\n", dataset_m_file); endfunction diff --git a/inst/+tblish/+internal/load_tablicious.m b/inst/+tblish/+internal/load_tablicious.m index 706d5be5..d82fd42c 100644 --- a/inst/+tblish/+internal/load_tablicious.m +++ b/inst/+tblish/+internal/load_tablicious.m @@ -23,7 +23,7 @@ for i_compat = 1:numel (shim_compat_levels) compat_lvl = shim_compat_levels{i_compat}; compat_dir = sprintf ("pre-%s", compat_lvl); - if compare_versions (version, compat_lvl, "<") + if (compare_versions (version, compat_lvl, "<")) addpath (fullfile (shims_dir, compat_dir)); endif endfor @@ -35,21 +35,21 @@ # of the main installation dir, which contains the inst/ files. But when # running from the repo, doc/ is a sibling of inst/. - if exist (fullfile (inst_dir, "doc", [pkg_name ".qch"]), "file") + if (exist (fullfile (inst_dir, "doc", [pkg_name ".qch"]), "file")) qhelp_file = fullfile (inst_dir, "doc", [pkg_name ".qch"]); - elseif exist (fullfile (fileparts (inst_dir), "doc", [pkg_name ".qch"]), "file") + elseif (exist (fullfile (fileparts (inst_dir), "doc", [pkg_name ".qch"]), "file")) qhelp_file = fullfile (fileparts (inst_dir), "doc", [pkg_name ".qch"]); else # Couldn't find doc file. Oh well. qhelp_file = []; endif - if ! isempty (qhelp_file) - if compare_versions (version, "4.4.0", ">=") && compare_versions (version, "6.0.0", "<") + if (! isempty (qhelp_file)) + if (compare_versions (version, "4.4.0", ">=") && compare_versions (version, "6.0.0", "<")) __octave_link_register_doc__ (qhelp_file); - elseif compare_versions (version, "6.0.0", ">=") && compare_versions (version, "7.1.0", "<") + elseif (compare_versions (version, "6.0.0", ">=") && compare_versions (version, "7.1.0", "<")) __event_manager_register_doc__ (qhelp_file); - elseif compare_versions (version, "7.1.0", ">=") + elseif (compare_versions (version, "7.1.0", ">=")) __event_manager_register_documentation__ (qhelp_file); endif endif diff --git a/inst/+tblish/+internal/parse_ismissing_indicator.m b/inst/+tblish/+internal/parse_ismissing_indicator.m index 62cc4448..8c96aa12 100644 --- a/inst/+tblish/+internal/parse_ismissing_indicator.m +++ b/inst/+tblish/+internal/parse_ismissing_indicator.m @@ -34,8 +34,8 @@ x = in; # Convert non-cells by breaking out elements or converting strings -if !iscell (x) - if ischar (x) +if (! iscell (x)) + if (ischar (x)) x = cellstr (x); else x = num2cell (x); @@ -47,13 +47,13 @@ # Validate for i = 1:numel (x) el = x{i}; - if ischar (el) - if size (el, 1) > 1 + if (ischar (el)) + if (size (el, 1) > 1) error ('ismissing: char indicator elements must be row vectors; element %d is %d rows high', ... i, size (el, 1)); endif else - if !isscalar (el) + if (! isscalar (el)) error ('ismissing: non-char indicator elements must be scalar; element %d is a %s %s', ... size2str (size (el)), class (el)); endif diff --git a/inst/+tblish/+internal/splitapply_impl.m b/inst/+tblish/+internal/splitapply_impl.m index 551f3ba3..ff29ea9f 100644 --- a/inst/+tblish/+internal/splitapply_impl.m +++ b/inst/+tblish/+internal/splitapply_impl.m @@ -21,7 +21,7 @@ mustBeA (func, 'function_handle'); narginchk (3, Inf); G = varargin{end}; - if ! isnumeric (G) + if (! isnumeric (G)) error ('splitapply: G, the last input argument, must be numeric; got a %s', ... class (G)); endif diff --git a/inst/+tblish/+internal/unload_tablicious.m b/inst/+tblish/+internal/unload_tablicious.m index 0212fc9c..eacb2b20 100644 --- a/inst/+tblish/+internal/unload_tablicious.m +++ b/inst/+tblish/+internal/unload_tablicious.m @@ -10,21 +10,21 @@ # Unregister doco - if exist (fullfile (inst_dir, "doc", [pkg_name ".qch"]), "file") + if (exist (fullfile (inst_dir, "doc", [pkg_name ".qch"]), "file")) qhelp_file = fullfile (inst_dir, "doc", [pkg_name ".qch"]); - elseif exist (fullfile (fileparts (inst_dir), "doc", [pkg_name ".qch"]), "file") + elseif (exist (fullfile (fileparts (inst_dir), "doc", [pkg_name ".qch"]), "file")) qhelp_file = fullfile (fileparts (inst_dir), "doc", [pkg_name ".qch"]); else # Couldn't find doc file. Oh well. qhelp_file = []; endif - if ! isempty (qhelp_file) - if compare_versions (version, "4.4.0", ">=") && compare_versions (version, "6.0.0", "<") + if (! isempty (qhelp_file)) + if (compare_versions (version, "4.4.0", ">=") && compare_versions (version, "6.0.0", "<")) __octave_link_unregister_doc__ (qhelp_file); - elseif compare_versions (version, "6.0.0", ">=") && compare_versions (version, "7.1.0", "<") + elseif (compare_versions (version, "6.0.0", ">=") && compare_versions (version, "7.1.0", "<")) __event_manager_unregister_doc__ (qhelp_file); - elseif compare_versions (version, "7.1.0", ">=") + elseif (compare_versions (version, "7.1.0", ">=")) __event_manager_unregister_documentation__ (qhelp_file); endif endif @@ -36,7 +36,7 @@ for i_compat = 1:numel (shim_compat_levels) compat_lvl = shim_compat_levels{i_compat}; compat_dir = sprintf ("pre-%s", compat_lvl); - if compare_versions (version, compat_lvl, "<") + if (compare_versions (version, compat_lvl, "<")) rmpath (fullfile (shims_dir, compat_dir)); endif endfor diff --git a/inst/+tblish/dataset.m b/inst/+tblish/dataset.m index 2da6825f..2eaefaed 100644 --- a/inst/+tblish/dataset.m +++ b/inst/+tblish/dataset.m @@ -58,8 +58,8 @@ function out = airmiles () name = 'airmiles'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -104,8 +104,8 @@ function out = AirPassengers () name = 'AirPassengers'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -197,8 +197,8 @@ function out = airquality () name = 'airquality'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -284,8 +284,8 @@ function out = anscombe () name = 'anscombe'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -353,8 +353,8 @@ function out = attenu () name = 'attenu'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -424,8 +424,8 @@ function out = attitude () name = 'attitude'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -481,8 +481,8 @@ function out = austres () name = 'austres'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -541,8 +541,8 @@ function out = beavers () name = 'beavers'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -604,8 +604,8 @@ function out = BJsales () name = 'BJsales'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -661,8 +661,8 @@ function out = BOD () name = 'BOD'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -749,8 +749,8 @@ function out = cars () name = 'cars'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -816,8 +816,8 @@ function out = ChickWeight () name = 'ChickWeight'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -892,8 +892,8 @@ function out = chickwts () name = 'chickwts'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -965,8 +965,8 @@ function out = co2 () name = 'co2'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -1067,8 +1067,8 @@ function out = crimtab () name = 'crimtab'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -1123,8 +1123,8 @@ function out = cupcake () name = 'cupcake'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -1184,8 +1184,8 @@ function out = discoveries () name = 'discoveries'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -1249,8 +1249,8 @@ function out = DNase () name = 'DNase'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -1315,8 +1315,8 @@ function out = esoph () name = 'esoph'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -1389,8 +1389,8 @@ function out = euro () name = 'euro'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -1444,8 +1444,8 @@ function out = eurodist () name = 'eurodist'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -1518,8 +1518,8 @@ function out = EuStockMarkets () name = 'EuStockMarkets'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -1601,8 +1601,8 @@ function out = faithful () name = 'faithful'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -1673,8 +1673,8 @@ function out = Formaldehyde () name = 'Formaldehyde'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -1753,8 +1753,8 @@ function out = freeny () name = 'freeny'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -1848,8 +1848,8 @@ function out = HairEyeColor () name = 'HairEyeColor'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -1906,8 +1906,8 @@ function out = Harman23cor () name = 'Harman23cor'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -1964,8 +1964,8 @@ function out = Harman74cor () name = 'Harman74cor'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -2025,8 +2025,8 @@ function out = Indometh () name = 'Indometh'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -2097,8 +2097,8 @@ function out = infert () name = 'infert'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -2160,8 +2160,8 @@ function out = InsectSprays () name = 'InsectSprays'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -2231,8 +2231,8 @@ function out = iris () name = 'iris'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -2291,8 +2291,8 @@ function out = islands () name = 'islands'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -2347,8 +2347,8 @@ function out = JohnsonJohnson () name = 'JohnsonJohnson'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -2409,8 +2409,8 @@ function out = LakeHuron () name = 'LakeHuron'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -2467,8 +2467,8 @@ function out = lh () name = 'lh'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -2551,8 +2551,8 @@ function out = LifeCycleSavings () name = 'LifeCycleSavings'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -2619,8 +2619,8 @@ function out = Loblolly () name = 'Loblolly'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -2693,8 +2693,8 @@ function out = longley () name = 'longley'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -2763,8 +2763,8 @@ function out = lynx () name = 'lynx'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -2837,8 +2837,8 @@ function out = morley () name = 'morley'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -2917,8 +2917,8 @@ function out = mtcars () name = 'mtcars'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -2979,8 +2979,8 @@ function out = nhtemp () name = 'nhtemp'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -3047,8 +3047,8 @@ function out = Nile () name = 'Nile'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -3103,8 +3103,8 @@ function out = nottem () name = 'nottem'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -3171,8 +3171,8 @@ function out = npk () name = 'npk'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -3223,8 +3223,8 @@ function out = occupationalStatus () name = 'occupationalStatus'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -3293,8 +3293,8 @@ function out = Orange () name = 'Orange'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -3376,8 +3376,8 @@ function out = OrchardSprays () name = 'OrchardSprays'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -3433,8 +3433,8 @@ function out = PlantGrowth () name = 'PlantGrowth'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -3493,8 +3493,8 @@ function out = precip () name = 'precip'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -3563,8 +3563,8 @@ function out = presidents () name = 'presidents'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -3634,8 +3634,8 @@ function out = pressure () name = 'pressure'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -3710,8 +3710,8 @@ function out = Puromycin () name = 'Puromycin'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -3784,8 +3784,8 @@ function out = quakes () name = 'quakes'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -3855,8 +3855,8 @@ function out = randu () name = 'randu'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -3914,8 +3914,8 @@ function out = rivers () name = 'rivers'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -3982,8 +3982,8 @@ function out = rock () name = 'rock'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -4052,8 +4052,8 @@ function out = sleep () name = 'sleep'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -4136,8 +4136,8 @@ function out = stackloss () name = 'stackloss'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -4222,8 +4222,8 @@ function out = state () name = 'state'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -4280,8 +4280,8 @@ function out = sunspot_month () name = 'sunspot_month'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -4337,8 +4337,8 @@ function out = sunspot_year () name = 'sunspot_year'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -4401,8 +4401,8 @@ function out = sunspots () name = 'sunspots'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -4489,8 +4489,8 @@ function out = swiss () name = 'swiss'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -4575,8 +4575,8 @@ function out = Theoph () name = 'Theoph'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -4668,8 +4668,8 @@ function out = Titanic () name = 'Titanic'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -4738,8 +4738,8 @@ function out = ToothGrowth () name = 'ToothGrowth'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -4799,8 +4799,8 @@ function out = treering () name = 'treering'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -4875,8 +4875,8 @@ function out = trees () name = 'trees'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -4956,8 +4956,8 @@ function out = UCBAdmissions () name = 'UCBAdmissions'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -5052,8 +5052,8 @@ function out = UKDriverDeaths () name = 'UKDriverDeaths'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -5111,8 +5111,8 @@ function out = UKgas () name = 'UKgas'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -5182,8 +5182,8 @@ function out = UKLungDeaths () name = 'UKLungDeaths'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -5235,8 +5235,8 @@ function out = USAccDeaths () name = 'USAccDeaths'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -5322,8 +5322,8 @@ function out = USArrests () name = 'USArrests'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -5398,8 +5398,8 @@ function out = USJudgeRatings () name = 'USJudgeRatings'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -5457,8 +5457,8 @@ function out = USPersonalExpenditure () name = 'USPersonalExpenditure'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -5516,8 +5516,8 @@ function out = uspop () name = 'uspop'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -5582,8 +5582,8 @@ function out = VADeaths () name = 'VADeaths'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -5645,8 +5645,8 @@ function out = volcano () name = 'volcano'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -5714,8 +5714,8 @@ function out = warpbreaks () name = 'warpbreaks'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -5785,8 +5785,8 @@ function out = women () name = 'women'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -5845,8 +5845,8 @@ function out = WorldPhones () name = 'WorldPhones'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -5899,8 +5899,8 @@ function out = WWWusage () name = 'WWWusage'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) @@ -5960,8 +5960,8 @@ function out = zCO2 () name = 'zCO2'; data = tblish.datasets.load(name); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel (vars) diff --git a/inst/+tblish/datasets.m b/inst/+tblish/datasets.m index 9f716ea0..9d8979d1 100644 --- a/inst/+tblish/datasets.m +++ b/inst/+tblish/datasets.m @@ -51,7 +51,7 @@ c = [c; {dset.name dset.summary}]; endfor out = cell2table(c, "VariableNames", {"Name", "Summary"}); - if nargout == 0 + if (nargout == 0) prettyprint (out); clear out endif @@ -71,8 +71,8 @@ function out = load (name) dset = tblish.internal.dataset.lookup (name); data = dset.load (); - if nargout == 0 - if isstruct (data) + if (nargout == 0) + if (isstruct (data)) s = data; vars = fieldnames (s); for i = 1:numel(vars) @@ -107,7 +107,7 @@ # this method and let it be replaced by "help tblish.dataset.". dset = tblish.internal.dataset.lookup (name); out = dset.description_texi; - if nargout == 0 + if (nargout == 0) disp (out); clear out endif diff --git a/inst/NaC.m b/inst/NaC.m index a084fe23..aa75b35a 100644 --- a/inst/NaC.m +++ b/inst/NaC.m @@ -41,7 +41,7 @@ #NaS Not-a-Categorical (missing-valued categorical array) # # Creates a categorical array with all-missing values. - if nargin == 0 + if (nargin == 0) out = categorical.undefined; else out = categorical.undefined (sz); diff --git a/inst/NaS.m b/inst/NaS.m index 9265dd27..fdd6fb44 100644 --- a/inst/NaS.m +++ b/inst/NaS.m @@ -41,7 +41,7 @@ #NaS Not-a-String (missing-valued string array) # # Creates a string array with all-missing values. - if nargin == 0 + if (nargin == 0) out = string.missing; else out = string.missing (sz); diff --git a/inst/NaT.m b/inst/NaT.m index 77d21846..5212c2e9 100644 --- a/inst/NaT.m +++ b/inst/NaT.m @@ -38,7 +38,7 @@ #NaT Not-a-Time # # Creates an array of datetimes with the value NaT. - if nargin == 0 + if (nargin == 0) out = datetime.NaT; else out = repmat (datetime.NaT, sz); diff --git a/inst/array2table.m b/inst/array2table.m index a9eb2711..000f9c1e 100644 --- a/inst/array2table.m +++ b/inst/array2table.m @@ -36,13 +36,13 @@ function out = array2table(c, varargin) #ARRAY2TABLE Convert an array to a table - if ndims (c) > 2 + if (ndims (c) > 2) error ('array2table: Input must be 2-D; got %d-D', ndims (c)); endif # Peel off trailing options [opts, args] = peelOffNameValueOptions (varargin, {'VariableNames', 'RowNames'}); - if !isempty (args) + if (! isempty (args)) error ('array2table: Unrecognized options'); endif @@ -52,7 +52,7 @@ colVals{iCol} = c(:,iCol); endfor - if isfield (opts, 'VariableNames') + if (isfield (opts, 'VariableNames')) varNames = opts.VariableNames; else varNames = cell (1, nCols); @@ -62,7 +62,7 @@ endif optArgs = {'VariableNames', varNames}; - if isfield (opts, 'RowNames') + if (isfield (opts, 'RowNames')) optArgs = [optArgs {'RowNames', opts.RowNames}]; endif out = table (colVals{:}, optArgs{:}); diff --git a/inst/calendarDuration.m b/inst/calendarDuration.m index ee018ebf..23d583f5 100644 --- a/inst/calendarDuration.m +++ b/inst/calendarDuration.m @@ -128,13 +128,13 @@ # Peel off options knownOptions = {'Format'}; opts = struct; - while numel (args) >= 3 && isa (args{end-1}, 'char') ... - && ismember (args{end-1}, knownOptions) + while (numel (args) >= 3 && isa (args{end-1}, 'char') ... + && ismember (args{end-1}, knownOptions)) opts.(args{end-1}) = args{end}; args(end-1:end) = []; endwhile # Parse inputs - switch numel (args) + switch (numel (args)) case 0 return case 1 @@ -142,7 +142,7 @@ Y = X(:,1); M = X(:,2); D = X(:,3); - if size(X, 2) > 3 + if (size(X, 2) > 3) T = X(:,4); else T = zeros (size (Y)); @@ -170,7 +170,7 @@ this.Days = D; this.Time = T; this.Sign = ones (size (Y)); - if isfield (opts, 'Format') + if (isfield (opts, 'Format')) this.Format = opts.Format; endif this = normalizeNaNs(this); @@ -256,13 +256,13 @@ ## @end deftypefn function out = plus (this, B) #PLUS Addition. - if !isa (this, 'calendarDuration') + if (! isa (this, 'calendarDuration')) error ('Left-hand side of + must be a calendarDuration'); endif - if isnumeric (B) + if (isnumeric (B)) B = calendarDuration.ofDays (B); endif - if isa (B, 'calendarDuration') + if (isa (B, 'calendarDuration')) out = this; out.Years = this.Years + (B.Sign .* B.Years); out.Months = this.Months + (B.Sign .* B.Months); @@ -287,18 +287,18 @@ ## @end deftypefn function out = times (this, B) #TIMES Array multiplication. - if isnumeric (this) && isa (B, 'calendarDuration') + if (isnumeric (this) && isa (B, 'calendarDuration')) out = times (B, this); endif - if !isa (this, 'calendarDuration') + if (! isa (this, 'calendarDuration')) error ('Left-hand side of * must be numeric or calendarDuration'); endif - if !isnumeric (B) + if (! isnumeric (B)) error ('B must be numeric; got a %s', class (B)); endif out = this; tfNeg = B < 0; - if any (any (tfNeg)) + if (any (any (tfNeg))) out.Sign(tfNeg) = -out.Sign(tfNeg); B = abs (B); endif @@ -329,7 +329,7 @@ function display (this) #DISPLAY Custom display. in_name = inputname (1); - if !isempty (in_name) + if (! isempty (in_name)) fprintf ('%s =\n', in_name); endif disp (this); @@ -337,7 +337,7 @@ function display (this) function disp (this) #DISP Custom display. - if isempty (this) + if (isempty (this)) fprintf ('Empty %s %s\n', size2str (size (this)), class (this)); return endif @@ -363,49 +363,50 @@ function disp (this) endmethods methods (Access = private) + function out = dispstrScalar (this) tblish.internal.chrono.mustBeScalar (this); - if isnat (this) + if (isnat (this)) out = 'NaT'; return endif els = {}; - if this.Sign < 0 + if (this.Sign < 0) els{end+1} = '-'; endif - if this.Years ~= 0 + if (this.Years != 0) els{end+1} = sprintf ('%dy', this.Years); endif - if this.Months ~= 0 + if (this.Months != 0) els{end+1} = sprintf ('%dmo', this.Months); endif - if this.Days ~= 0 + if (this.Days != 0) els{end+1} = sprintf ('%dd', this.Days); endif - if this.Time ~= 0 + if (this.Time != 0) time_str = dispstrs (duration.ofDays (this.Time)); time_str = time_str{1}; els{end+1} = time_str; endif - if isempty (els) + if (isempty (els)) els = {'0d'}; endif out = strjoin (els, ' '); endfunction - function out = sprintf(fmt, varargin) + function out = sprintf (fmt, varargin) args = varargin; for i = 1:numel (args) - if isa (args{i}, 'calendarDuration') + if (isa (args{i}, 'calendarDuration')) args{i} = dispstr (args{i}); endif endfor out = sprintf (fmt, args{:}); endfunction - function out = fprintf(varargin) + function out = fprintf (varargin) args = varargin; - if isnumeric (args{1}) + if (isnumeric (args{1})) fid = args{1}; args(1) = []; else @@ -414,11 +415,11 @@ function disp (this) fmt = args{1}; args(1) = []; for i = 1:numel (args) - if isa (args{i}, 'calendarDuration') + if (isa (args{i}, 'calendarDuration')) args{i} = dispstr (args{i}); endif endfor - if isempty (fid) + if (isempty (fid)) fprintf (fmt, args{:}); else fprintf (fid, fmt, args{:}); @@ -439,6 +440,7 @@ function disp (this) this.Time(tfNaN) = NaN; endif endfunction + endmethods # Planar boilerplate stuff @@ -457,7 +459,7 @@ function disp (this) function out = size (this, dim) #SIZE Size of array. - if nargin == 1 + if (nargin == 1) out = size (this.Sign); else out = size (this, dim); @@ -617,7 +619,7 @@ function disp (this) #CAT Concatenate arrays. args = varargin; for i = 1:numel (args) - if !isa (args{i}, 'calendarDuration') + if (! isa (args{i}, 'calendarDuration')) args{i} = calendarDuration (args{i}); endif endfor @@ -650,7 +652,7 @@ function disp (this) #SUBSASGN Subscripted assignment. # Chained subscripts - if numel (s) > 1 + if (numel (s) > 1) rhs_in = subsref (this, s(1)); rhs = subsasgn (rhs_in, s(2:end), b); else @@ -658,7 +660,7 @@ function disp (this) endif # Base case - switch s(1).type + switch (s(1).type) case '()' this = subsasgnParensPlanar (this, s(1), rhs); case '{}' @@ -672,7 +674,7 @@ function disp (this) #SUBSREF Subscripted reference. # Base case - switch s(1).type + switch (s(1).type) case '()' out = subsrefParensPlanar (this, s(1)); case '{}' @@ -682,14 +684,14 @@ function disp (this) endswitch # Chained reference - if numel (s) > 1 + if (numel (s) > 1) out = subsref (out, s(2:end)); endif endfunction - function [out,Indx] = sort (this) + function [out, Indx] = sort (this) #SORT Sort array elements. - if isvector (this) + if (isvector (this)) isRow = isrow (this); this = subset (this, ':'); # NaNs sort stably to end, so handle them separately @@ -705,7 +707,7 @@ function disp (this) if isRow out = out'; endif - elseif ismatrix (this) + elseif (ismatrix (this)) out = this; Indx = NaN (size (out)); for iCol = 1:size (this, 2) @@ -721,29 +723,29 @@ function disp (this) nDims = ndims (this); # Can't have a space after "repmat" or you get a syntax error ixs = [{':'} repmat({1}, [1 nDims-1])]; - while true + while (true) col = subset (this, ixs{:}); [sortedCol,sortIx] = sort (col); Indx(ixs{:}) = sortIx; out = asgn (out, ixs, sortedCol); ixs{end} = ixs{end}+1; for iDim = nDims:-1:3 - if ixs{iDim} > sz(iDim) + if (ixs{iDim} > sz(iDim)) ixs{iDim-1} = ixs{iDim-1} + 1; ixs{iDim} = 1; endif endfor - if ixs{2} > sz(2) - break; + if (ixs{2} > sz(2)) + break endif endwhile endif endfunction - function [out,Indx] = unique (this, varargin) + function [out, Indx] = unique (this, varargin) #UNIQUE Set unique. flags = setdiff (varargin, {'rows'}); - if ismember ('rows', varargin) + if (ismember ('rows', varargin)) [~,proxyIx] = unique (this); proxyIx = reshape (proxyIx, size (this)); [~,Indx] = unique (proxyIx, 'rows', flags{:}); @@ -756,51 +758,51 @@ function disp (this) nonnans = subset (this, !tfNaN); ixNonnan = find (!tfNaN); keys = proxyKeys (nonnans); - if isa (keys, 'table') + if (isa (keys, 'table')) [~,ix] = unique (keys, flags{:}); else [~,ix] = unique (keys, 'rows', flags{:}); endif out = [subset(nonnans, ix); nans]; Indx = [ixNonnan(ix); find(tfNaN)]; - if isRow + if (isRow) out = out'; endif endif endfunction - function [out,Indx] = ismember (a, b, varargin) + function [out, Indx] = ismember (a, b, varargin) #ISMEMBER True for set member. - if ismember ('rows', varargin) + if (ismember ('rows', varargin)) error ('ismember(..., ''rows'') is unsupported'); endif - if !isa (a, 'calendarDuration') + if (! isa (a, 'calendarDuration')) a = calendarDuration (a); endif - if !isa (b, 'calendarDuration') + if (! isa (b, 'calendarDuration')) b = calendarDuration (b); endif [proxyA, proxyB] = proxyKeys (a, b); - [out,Indx] = ismember (proxyA, proxyB, 'rows'); + [out, Indx] = ismember (proxyA, proxyB, 'rows'); out = reshape (out, size (a)); Indx = reshape (Indx, size (a)); endfunction - function [out,Indx] = setdiff (a, b, varargin) + function [out, Indx] = setdiff (a, b, varargin) #SETDIFF Set difference. - if ismember ('rows', varargin) + if (ismember ('rows', varargin)) error ('setdiff(..., ''rows'') is unsupported'); endif - [tf,~] = ismember (a, b); + [tf, ~] = ismember (a, b); out = parensRef (a, !tf); Indx = find (!tf); - [out,ix] = unique (out); + [out, ix] = unique (out); Indx = Indx(ix); endfunction function [out,ia,ib] = intersect (a, b, varargin) #INTERSECT Set intersection. - if ismember ('rows', varargin) + if (ismember ('rows', varargin)) error ('intersect(..., ''rows'') is unsupported'); endif [proxyA, proxyB] = proxyKeys (a, b); @@ -810,7 +812,7 @@ function disp (this) function [out,ia,ib] = union (a, b, varargin) #UNION Set union. - if ismember ('rows', varargin) + if (ismember ('rows', varargin)) error ('union(..., ''rows'') is unsupported'); endif [proxyA, proxyB] = proxyKeys (a, b); @@ -827,7 +829,7 @@ function disp (this) function this = subsasgnParensPlanar (this, s, rhs) #SUBSASGNPARENSPLANAR ()-assignment for planar object - if !isa (rhs, 'calendarDuration') + if (! isa (rhs, 'calendarDuration')) rhs = calendarDuration (rhs); endif this.Sign(s.subs{:}) = rhs.Sign; @@ -867,7 +869,7 @@ function disp (this) # This is what you call internally inside the class instead of doing # ()-indexing references on the LHS, which don't work properly inside # the class because they don't respect the subsasgn() override. - if !iscell (ix) + if (! iscell (ix)) ix = { ix }; endif s.type = '()'; diff --git a/inst/calmonths.m b/inst/calmonths.m index 75228a1b..5c213e3c 100644 --- a/inst/calmonths.m +++ b/inst/calmonths.m @@ -35,7 +35,7 @@ function out = calmonths (x) #CALMONTHS Calendar duration in months - if !isnumeric (x) + if (! isnumeric (x)) error ('Input must be numeric'); endif out = calendarDuration (0, x, 0); diff --git a/inst/calyears.m b/inst/calyears.m index 295ee5f4..a5798213 100644 --- a/inst/calyears.m +++ b/inst/calyears.m @@ -29,7 +29,7 @@ function out = calyears (x) #CALYEARS Calendar duration in years - if !isnumeric (x) + if (! isnumeric (x)) error ('Input must be numeric'); endif out = calendarDuration (x, 0, 0); diff --git a/inst/categorical.m b/inst/categorical.m index c32cab8f..706d29ee 100644 --- a/inst/categorical.m +++ b/inst/categorical.m @@ -107,12 +107,12 @@ function out = from_codes (codes, cats, varargin) [opts, args] = peelOffNameValueOptions (varargin, {'Ordinal', 'Protected'}); isOrdinal = false; - if isfield (opts, 'Ordinal') + if (isfield (opts, 'Ordinal')) mustBeScalarLogical (opts.Ordinal, 'Ordinal option'); isOrdinal = opts.Ordinal; endif isProtected = false; - if isfield (opts, 'Protected') + if (isfield (opts, 'Protected')) mustBeScalarLogical (opts.Protected, 'Protected option'); isProtected = opts.Protected; endif @@ -120,7 +120,7 @@ cats = cats(:)'; code = uint16 (codes); - if ! isa (codes, 'uint16') + if (! isa (codes, 'uint16')) # TODO: Check for clean conversion endif @@ -153,7 +153,7 @@ ## ## @end deftypefn function out = undefined (sz) - if nargin < 1 || isempty (sz) + if (nargin < 1 || isempty (sz)) sz = [1 1]; endif out = categorical; @@ -181,7 +181,7 @@ ## ## @end deftypefn function out = missing (sz) - if nargin == 0 + if (nargin == 0) out = categorical.undefined; else out = categorical.undefined (sz); @@ -235,23 +235,23 @@ # num2str representation of numbers instead, and make those all categories. # TODO: Support objects. - if nargin == 0 + if (nargin == 0) return endif validOptions = {'Ordinal', 'Protected'}; [opts, args] = peelOffNameValueOptions (varargin, validOptions); - if ischar (x) + if (ischar (x)) x = cellstr (x); endif - if numel (args) >= 1 + if (numel (args) >= 1) valueset = args{1}; valueset = valueset(:)'; - if any (ismissing (valueset)) + if (any (ismissing (valueset))) error ('categorical:InvalidInput', 'categorical: Cannot have missing values in valueset'); endif u_valueset = unique (valueset); - if numel (u_valueset) < numel (valueset) + if (numel (u_valueset) < numel (valueset)) error ("categorical:InvalidInput", ... "categorical: Non-unique values in valueset; valueset values must be unique."); endif @@ -259,31 +259,31 @@ valueset = unique (x); valueset = valueset(!ismissing (valueset)); endif - if numel (args) >= 2 + if (numel (args) >= 2) category_names = args{2}; else - if isa (valueset, 'string') || iscellstr (valueset) + if (isa (valueset, 'string') || iscellstr (valueset)) category_names = cellstr (valueset); else category_names = dispstrs (valueset); endif endif doProtected = false; - if isfield (opts, 'Protected') + if (isfield (opts, 'Protected')) mustBeScalarLogical (opts.Protected, 'Protected option'); doProtected = opts.Protected; endif doOrdinal = false; - if isfield (opts, 'Ordinal') + if (isfield (opts, 'Ordinal')) mustBeScalarLogical (opts.Ordinal, 'Ordinal option'); doOrdinal = opts.Ordinal; endif - if doOrdinal + if (doOrdinal) doProtected = true; endif [tf, loc] = ismember (x, valueset); - if any(loc > intmax ('uint16')) + if (any (loc > intmax ('uint16'))) error (['Category count out of range: categorical supports a max of %d ' ... 'categories; this input has %d'], intmax ('uint16'), max (loc)); endif @@ -315,12 +315,12 @@ endfunction function this = set.code (this, x) - if ! isnumeric (x) + if (! isnumeric (x)) error ('categorical.code: values must be numeric'); endif code = uint16 (x); - if ! isa (x, 'uint16') - if ! all (code(:) == x(:)) + if (! isa (x, 'uint16')) + if (! all (code(:) == x(:))) error ('categorical.code: input did not convert cleanly to uint16'); endif endif @@ -420,21 +420,21 @@ function display (this) #DISPLAY Custom display in_name = inputname(1); - if !isempty(in_name) - fprintf('%s =\n', in_name); + if (! isempty(in_name)) + fprintf ('%s =\n', in_name); endif - disp(this); + disp (this); endfunction function disp (this) #DISP Custom display - if isempty (this) + if (isempty (this)) fprintf ('Empty %s categorical\n', size2str (size (this))); return endif my_dispstrs = this.dispstrs; out = format_dispstr_array (my_dispstrs); - fprintf("%s", out); + fprintf ("%s", out); endfunction ## -*- texinfo -*- @@ -457,7 +457,7 @@ function disp (this) endfunction function out = dispstr (this) - if isscalar (this) + if (isscalar (this)) d = dispstrs (this); out = d{1}; else @@ -465,19 +465,19 @@ function disp (this) endif endfunction - function out = sprintf(fmt, varargin) + function out = sprintf (fmt, varargin) args = varargin; for i = 1:numel (args) - if isa (args{i}, 'categorical') + if (isa (args{i}, 'categorical')) args{i} = dispstr (args{i}); endif endfor out = sprintf (fmt, args{:}); endfunction - function out = fprintf(varargin) + function out = fprintf (varargin) args = varargin; - if isnumeric (args{1}) + if (isnumeric (args{1})) fid = args{1}; args(1) = []; else @@ -486,11 +486,11 @@ function disp (this) fmt = args{1}; args(1) = []; for i = 1:numel (args) - if isa (args{i}, 'categorical') + if (isa (args{i}, 'categorical')) args{i} = dispstr (args{i}); endif endfor - if isempty (fid) + if (isempty (fid)) fprintf (fmt, args{:}); else fprintf (fid, fmt, args{:}); @@ -540,12 +540,12 @@ function summary (this) narginchk (2, 2); newcats = cellstr (newcats); newcats = newcats(:)'; - if this.isOrdinal + if (this.isOrdinal) error (['categorical.addcats: Adding categories for Ordinal arrays is ' ... 'not implemented yet. Sorry.']); endif [tf, loc] = ismember (newcats, this.cats); - if any (tf) + if (any (tf)) error ('categorical.addcats: Categories are already present in input: %s', ... strjoin (newcats(tf), ', ')); endif @@ -574,7 +574,7 @@ function summary (this) ## ## @end deftypefn function out = removecats (this, oldcats) - if nargin == 1 + if (nargin == 1) out = squeezecats (this); return endif @@ -607,17 +607,17 @@ function summary (this) function out = mergecats (this, oldcats, newcat) narginchk (2, 3); mustBeNonEmpty (oldcats); - if nargin < 3 + if (nargin < 3) newcat = oldcats{1}; endif oldcats = cellstr (oldcats); - if this.isOrdinal + if (this.isOrdinal) error ('categorical: Merging of ordinal categories is not yet implemented. Sorry.'); endif [tf, old_cat_codes] = ismember (oldcats, this.cats); - if ! all (tf) + if (! all (tf)) # TODO: I don't know if this should be an error, or just silently ignored -apj error ('categorical.mergecats: Specified categories not present in input: %s', ... strjoin(oldcats(!tf), ', ')); @@ -625,7 +625,7 @@ function summary (this) [is_current_cat, new_cat_code] = ismember (newcat, this.cats) out = this; - if is_current_cat + if (is_current_cat) # Merge into existing category cats_to_delete = setdiff (oldcats, newcat); [tf, loc] = ismember (this.code, old_cat_codes); @@ -655,7 +655,7 @@ function summary (this) ## @end deftypefn function out = renamecats (this, varargin) narginchk (2, 3); - if nargin == 2 + if (nargin == 2) oldnames = this.cats; newnames = varargin{1}; else @@ -666,14 +666,14 @@ function summary (this) oldnames = oldnames(:)'; newnames = cellstr (newnames); newnames = newnames(:)'; - if ! isequal (size (oldnames), size (newnames)); + if (! isequal (size (oldnames), size (newnames))) error (['categorical.renamecats: Inconsistent dimensions for oldnames ' ... 'and newnames: %s vs %s'], size2str (size (oldnames)), size2str (size (newnames))); endif out = this; [tf, loc] = ismember (oldnames, this.cats); - if ! all (tf) + if (! all (tf)) error ('categorical.renamecats: Specified categories do not exist in input: %s', ... strjoin (oldnames(!tf), ', ')); endif @@ -695,12 +695,12 @@ function summary (this) ## ## @end deftypefn function out = reordercats (this, newcats) - if nargin == 1 + if (nargin == 1) newcats = sort (this.cats); endif newcats = cellstr (newcats); newcats = newcats(:)'; - if ! isequal (sort (newcats), sort (this.cats)) + if (! isequal (sort (newcats), sort (this.cats))) error ('categorical.reordercats: newcats and oldcats must be the same sets, just reordered'); endif @@ -727,14 +727,14 @@ function summary (this) newcats = cellstr (newcats); newcats = newcats(:)'; - if this.isOrdinal + if (this.isOrdinal) error ('categorical.setcats: Cannot set categories on Ordinal categorical arrays'); endif [tf, loc] = ismember (this.cats, newcats); loc(!tf) = 0; codes = codes_with_nans (this); - new_codes = NaN(size(codes)); + new_codes = NaN (size(codes)); new_codes(!isnan(codes)) = loc(codes(!isnan(codes))); out = this; out.code = uint16 (new_codes); @@ -824,15 +824,15 @@ function summary (this) # categories on the categorical input. Whether that is required should be # determined by the Protected property; non-Protected categoricals may expand # their set of categories automatically. - if ! isa (A, 'categorical') - if isordinal (B) + if (! isa (A, 'categorical')) + if (isordinal (B)) B = promote_to_existing_categories (A, B); else A = categorical (A); endif endif - if ! isa (B, 'categorical') - if isordinal (A) + if (! isa (B, 'categorical')) + if (isordinal (A)) B = promote_to_existing_categories (B, A); else B = categorical (B); @@ -840,10 +840,10 @@ function summary (this) endif # Unify their category definitions - if isequal (A.cats, B.cats) + if (isequal (A.cats, B.cats)) return endif - if isordinal (A) || isordinal (B) + if (isordinal (A) || isordinal (B)) error ('categorical: cannot unify different categories for Ordinal categorical arrays'); endif [A, B] = unify_nonordinal_categories (A, B); @@ -854,16 +854,16 @@ function summary (this) mustBeA (B, 'categorical'); # TODO: In the protected case, eliminate categories that have no values on # the non-protected side, to avoid possibly-spurious errors. - if A.isProtected + if (A.isProtected) cats_only_in_B = setdiff (B.cats, A.cats); - if ! isempty (cats_only_in_B) + if (! isempty (cats_only_in_B)) error ('categorical: input A is Protected, but input B has categories not in A: %s', ... strjoin (cats_only_in_B, ', ')); endif endif - if B.isProtected + if (B.isProtected) cats_only_in_A = setdiff (A.cats, B.cats); - if ! isempty (cats_only_in_A) + if (! isempty (cats_only_in_A)) error ('categorical: input B is Protected, but input A has categories not in B: %s', ... strjoin (cats_only_in_A, ', ')); endif @@ -1030,7 +1030,7 @@ function summary (this) function out = size (this, dim) #SIZE Size of array. - if nargin == 1 + if (nargin == 1) out = size (this.code); else out = size (this.code, dim); @@ -1127,7 +1127,7 @@ function summary (this) function [this, nshifts] = shiftdim( this, n) #SHIFTDIM Shift dimensions. - if nargin > 1 + if (nargin > 1) this.code = shiftdim (this.code, n); this.tfMissing = shiftdim (this.code, n); else @@ -1140,7 +1140,7 @@ function summary (this) #CAT Concatenate arrays. args = varargin; for i = 1:numel(args) - if !isa(args{i}, 'categorical') + if (! isa(args{i}, 'categorical')) args{i} = categorical(args{i}); endif endfor @@ -1169,7 +1169,7 @@ function summary (this) #SUBSASGN Subscripted assignment. # Chained subscripts - if numel(s) > 1 + if (numel(s) > 1) rhs_in = subsref(this, s(1)); rhs = subsasgn(rhs_in, s(2:end), b); else @@ -1177,7 +1177,7 @@ function summary (this) endif # Base case - switch s(1).type + switch (s(1).type) case '()' this = subsasgnParensPlanar(this, s(1), rhs); case '{}' @@ -1193,7 +1193,7 @@ function summary (this) #SUBSREF Subscripted reference. # Base case - switch s(1).type + switch (s(1).type) case '()' varargout = { subsrefParensPlanar(this, s(1)) }; case '{}' @@ -1215,7 +1215,7 @@ function summary (this) endswitch # Chained reference - if numel (s) > 1 + if (numel (s) > 1) out = subsref (out, s(2:end)); endif endfunction @@ -1223,7 +1223,7 @@ function summary (this) endmethods methods - function varargout = promote_to_existing_categories(this, varargin) + function varargout = promote_to_existing_categories (this, varargin) # Convert strings or numerics to categorical, using an existing categorical # # varargout = promote_to_existing_categories(this, varargin) @@ -1234,12 +1234,12 @@ function summary (this) varargout = cell (size (varargin)); for i_arg = 1:numel(varargin) arg = varargin{i_arg}; - if isa (arg, 'categorical') + if (isa (arg, 'categorical')) error ('promote_to_existing_categories: categorical input is not supported yet.'); elseif isstring (arg) || iscellstr (arg) [tfMember, loc] = ismember (arg, this.cats); tfBad = !tfMember & !ismissing (arg); - if any (tfBad) + if (any (tfBad)) error('input string had values that were not members of this''s categories'); endif code = loc; @@ -1260,7 +1260,7 @@ function summary (this) function this = subsasgnParensPlanar (this, s, rhs) #SUBSASGNPARENSPLANAR ()-assignment for planar object - if !isa (rhs, 'categorical') + if (! isa (rhs, 'categorical')) # TODO: This conversion is probably wrong. It probably needs to be done # with respect to this's existing cats list [this, rhs] = promote2 (this, rhs); @@ -1269,19 +1269,19 @@ function summary (this) this.tfMissing(s.subs{:}) = rhs.tfMissing; endfunction - function out = subsrefParensPlanar(this, s) + function out = subsrefParensPlanar (this, s) #SUBSREFPARENSPLANAR ()-indexing for planar object out = this; out.code = this.code(s.subs{:}); out.tfMissing = this.tfMissing(s.subs{:}); endfunction - function out = parensRef(this, varargin) + function out = parensRef (this, varargin) #PARENSREF ()-indexing, for this class's internal use out = subsrefParensPlanar (this, struct ('subs', {varargin})); endfunction - function out = subset(this, varargin) + function out = subset (this, varargin) #SUBSET Subset array by indexes. # This is what you call internally inside the class instead of doing # ()-indexing references on the RHS, which don't work properly inside the class @@ -1289,17 +1289,17 @@ function summary (this) out = parensRef (this, varargin{:}); endfunction - function out = asgn(this, ix, value) + function out = asgn (this, ix, value) #ASGN Assign array elements by indexes. # This is what you call internally inside the class instead of doing # ()-indexing references on the LHS, which don't work properly inside # the class because they don't respect the subsasgn() override. - if !iscell(ix) + if (! iscell(ix)) ix = { ix }; endif s.type = '()'; s.subs = ix; - out = subsasgnParensPlanar(this, s, value); + out = subsasgnParensPlanar (this, s, value); endfunction endmethods @@ -1316,7 +1316,7 @@ function summary (this) cat_codes_to_rm = cat_codes_to_rm(tf); cats_to_delete2 = cats_to_delete(tf); [tf_code_used, loc] = ismember (cat_codes_to_rm, this.code); - if any (tf_code_used) + if (any (tf_code_used)) error ('categorical: Internal error: some categories to delete are still in use: %s', ... strjoin (cats_to_delete2(tf_code_used), ', ')); endif diff --git a/inst/cell2table.m b/inst/cell2table.m index 9a586eea..a9c212e4 100644 --- a/inst/cell2table.m +++ b/inst/cell2table.m @@ -29,33 +29,33 @@ ## See also: @ref{array2table}, @ref{table}, @ref{struct2table} ## ## @end deftypefn -function out = cell2table(c, varargin) +function out = cell2table (c, varargin) #CELL2TABLE Convert a cell array to a table - if !iscell (c) + if (! iscell (c)) error ('cell2table: Input must be cell; got %s', class (c)); endif - if ndims (c) > 2 + if (ndims (c) > 2) error ('cell2table: Input must be 2-D; got %d-D', ndims (c)); endif # Peel off trailing options [opts, args] = peelOffNameValueOptions (varargin, {'VariableNames', 'RowNames'}); - if !isempty (args) + if (! isempty (args)) error ('cell2table: Unrecognized options'); endif nCols = size (c, 2); colVals = cell (1, nCols); for iCol = 1:nCols - if iscellstr (c(:,iCol)) + if (iscellstr (c(:,iCol))) # Special-case char conversion colVals{iCol} = c(:,iCol); else # Cheap hack to test for cat-ability try x = cat (1, c{:,iCol}); - if size (x, 1) == size (c, 1) + if (size (x, 1) == size (c, 1)) colVals{iCol} = x; continue endif @@ -66,7 +66,7 @@ endif endfor - if isfield (opts, 'VariableNames') + if (isfield (opts, 'VariableNames')) varNames = opts.VariableNames; else varNames = cell (1, nCols); @@ -76,7 +76,7 @@ endif optArgs = {'VariableNames', varNames}; - if isfield (opts, 'RowNames') + if (isfield (opts, 'RowNames')) optArgs = [optArgs {'RowNames', opts.RowNames}]; endif out = table (colVals{:}, optArgs{:}); diff --git a/inst/colvecfun.m b/inst/colvecfun.m index 2fd8afaf..eb6b4622 100644 --- a/inst/colvecfun.m +++ b/inst/colvecfun.m @@ -32,7 +32,7 @@ ## @end deftypefn function out = colvecfun (fcn, x) narginchk (2, 2); - if ! isa (fcn, 'function_handle') + if (! isa (fcn, 'function_handle')) error ('colvecfun: input fcn must be a function handle; got a %s', class (fcn)); endif @@ -43,7 +43,7 @@ function out = colvecfun_impl (fcn, x) - switch ndims (x) + switch (ndims (x)) case 1 out = colvecfun_for_1_dims (fcn, x); case 2 diff --git a/inst/contains.m b/inst/contains.m index 41b62831..7fa7cfb0 100644 --- a/inst/contains.m +++ b/inst/contains.m @@ -36,7 +36,7 @@ [opts, args] = peelOffNameValueOptions (varargin, {'IgnoreCase'}); ignore_case = false; - if isfield (opts, 'IgnoreCase') + if (isfield (opts, 'IgnoreCase')) mustBeScalarLogical (opts.IgnoreCase, 'IgnoreCase option'); ignore_case = opts.IgnoreCase; endif @@ -44,7 +44,7 @@ str = cellstr (str); pattern = cellstr (pattern); - if any (cellfun ('isempty', pattern(:))) + if (any (cellfun ('isempty', pattern(:)))) out = true (size (str)); return; endif @@ -53,7 +53,7 @@ # full string for multiple matches. Could replace this whole function with # an oct-file that does efficient scanning. - if ignore_case + if (ignore_case) str = lower (str); pattern = lower (pattern); endif @@ -63,7 +63,7 @@ pat = pattern{i_pattern}; ix = strfind (str{i_str}, pattern{i_pattern}); tf = ! isempty (ix); - if tf + if (tf) out(i_str) = true; break endif diff --git a/inst/datetime.m b/inst/datetime.m index 55aece18..d67da593 100644 --- a/inst/datetime.m +++ b/inst/datetime.m @@ -131,33 +131,33 @@ args = varargin; knownOptions = {'Format','InputFormat','Locale','PivotYear','TimeZone'}; opts = struct; - while numel (args) >= 3 && isa (args{end-1}, 'char') ... - && ismember (args{end-1}, knownOptions) + while (numel (args) >= 3 && isa (args{end-1}, 'char') ... + && ismember (args{end-1}, knownOptions)) opts.(args{end-1}) = args{end}; args(end-1:end) = []; endwhile # Handle inputs timeZone = ''; - if isfield (opts, 'TimeZone') + if (isfield (opts, 'TimeZone')) timeZone = opts.TimeZone; endif - switch numel (args) + switch (numel (args)) case 0 dnums = now; case 1 x = args{1}; - if isnumeric (x) + if (isnumeric (x)) # Convert date vectors dnums = datenum (x); - elseif ischar (x) || iscellstr (x) || isa (x, 'string') + elseif (ischar (x) || iscellstr (x) || isa (x, 'string')) x = cellstr (x); tfRelative = ismember (x, {'today','tomorrow','yesterday','now'}); - if all (tfRelative) - if !isscalar (x) + if (all (tfRelative)) + if (! isscalar (x)) error ('Multiple arguments not allowed for relativeDay format'); endif - switch x{1} + switch (x{1}) case 'yesterday' dnums = floor (now) - 1; case 'today' @@ -170,41 +170,41 @@ else # They're datestrs # TODO: Support Locale option - if isfield (opts, 'Locale') + if (isfield (opts, 'Locale')) error ('Locale option is unimplemented'); endif # TODO: Support PivotYear option - if isfield (opts, 'PivotYear') + if (isfield (opts, 'PivotYear')) error ('PivotYear option is unimplemented'); endif - if isfield (opts, 'TimeZone') + if (isfield (opts, 'TimeZone')) timeZone = opts.TimeZone; endif - if isfield (opts, 'InputFormat') + if (isfield (opts, 'InputFormat')) dnums = datenum (x, opts.InputFormat); else dnums = datenum (x); endif dnums = reshape (dnums, size(x)); endif - elseif isstruct (x) + elseif (isstruct (x)) error ('datetime: struct to datetime conversion has not been spec''ed or implemented yet'); - elseif ismember (class (x), {'java.util.Date', 'java.util.Date[]', 'java.time.TemporalAccessor', ... - 'java.time.TemporalAccessor[]'}) + elseif (ismember (class (x), {'java.util.Date', 'java.util.Date[]', 'java.time.TemporalAccessor', ... + 'java.time.TemporalAccessor[]'})) error ('datetime: Java date conversion is not implemented yet. Sorry.'); else error ('datetime: Invalid input type: %s', class (x)); endif case 2 # Undocumented calling form for Tablicious's internal use - if !isequal (args{2}, 'Backdoor') + if (! isequal (args{2}, 'Backdoor')) error ('Invalid number of inputs (excluding options): %d', numel (args)); endif dnums = args{1}; case 3 [in1, in2, in3] = args{:}; - if isequal (in2, 'ConvertFrom') - switch in3 + if (isequal (in2, 'ConvertFrom')) + switch (in3) case 'datenum' dnums = double (in1); case 'posixtime' @@ -214,7 +214,7 @@ error ('Unsupported ConvertFrom format: %s', in3); # TODO: Implement more formats endswitch - elseif isnumeric (in2) + elseif (isnumeric (in2)) [Y, M, D] = varargin{:}; dnums = datenum (Y, M, D); else @@ -235,14 +235,14 @@ endswitch # Construct - if !isempty (timeZone) + if (! isempty (timeZone)) this.TimeZone = timeZone; - if !isequal (timeZone, 'UTC') + if (! isequal (timeZone, 'UTC')) dnums = datetime.convertDatenumTimeZone(dnums, timeZone, 'UTC'); endif endif this.dnums = dnums; - if isfield (opts, 'Format') + if (isfield (opts, 'Format')) this.Format = opts.Format; endif endfunction @@ -380,17 +380,17 @@ endfunction function this = set.TimeZone (this, x) - if !ischar (x) || ! (isrow (x) || isempty (x)) + if (! ischar (x) || ! (isrow (x) || isempty (x))) error ('TimeZone must be a char row vector; got a %s %s', ... size2str (size (x)), class (x)); endif tzdb = tblish.internal.chrono.tzinfo.TzDb.instance; - if ! isempty (x) && ! ismember (x, tzdb.definedZones) + if (! isempty (x) && ! ismember (x, tzdb.definedZones)) error ('Undefined TimeZone: %s', x); endif - if isempty (this.TimeZone) && ! isempty (x) + if (isempty (this.TimeZone) && ! isempty (x)) this.dnums = datetime.convertDatenumTimeZone (this.dnums, x, 'UTC'); - elseif ! isempty (this.TimeZone) && isempty (x) + elseif (! isempty (this.TimeZone) && isempty (x)) this.dnums = datetime.convertDatenumTimeZone (this.dnums, 'UTC', this.TimeZone); endif this.TimeZone = x; @@ -582,13 +582,13 @@ ## ## @end deftypefn function out = week (this) - error('week() is unimplemented'); + error ('week() is unimplemented'); endfunction function display (this) #DISPLAY Custom display. in_name = inputname (1); - if !isempty (in_name) + if (! isempty (in_name)) fprintf ('%s =\n', in_name); endif disp (this); @@ -596,19 +596,19 @@ function display (this) function disp (this) #DISP Custom display. - if isempty (this) + if (isempty (this)) fprintf ('Empty %s %s\n', size2str (size (this)), class (this)); - elseif isscalar (this) + elseif (isscalar (this)) str = dispstrs (this); str = str{1}; - if !isempty (this.TimeZone) + if (! isempty (this.TimeZone)) str = [str ' ' this.TimeZone]; endif fprintf (' %s\n', str); else txt = tblish.internal.chrono.format_dispstr_array (dispstrs (this)); fprintf ('%s\n', txt); - if !isempty (this.TimeZone) + if (! isempty (this.TimeZone)) fprintf (' %s\n', this.TimeZone); endif endif @@ -626,7 +626,7 @@ function disp (this) function out = dispstrs (this) # TODO: Uh oh; TimeZone isn't included in the output here! - if isempty (this.TimeZone) + if (isempty (this.TimeZone)) local_dnums = this.dnums; else local_dnums = datetime.convertDatenumTimeZone (this.dnums, 'UTC', this.TimeZone); @@ -634,7 +634,7 @@ function disp (this) out = cell (size (this)); tfNaN = isnan (local_dnums); out(tfNaN) = {'NaT'}; - if any(!tfNaN(:)) + if (any (!tfNaN(:))) out(!tfNaN) = cellstr (datestr (local_dnums(!tfNaN))); endif endfunction @@ -680,7 +680,7 @@ function disp (this) function out = sprintf(fmt, varargin) args = varargin; for i = 1:numel (args) - if isa (args{i}, 'datetime') + if (isa (args{i}, 'datetime')) args{i} = datestr (args{i}); endif endfor @@ -689,7 +689,7 @@ function disp (this) function out = fprintf(varargin) args = varargin; - if isnumeric (args{1}) + if (isnumeric (args{1})) fid = args{1}; args(1) = []; else @@ -698,11 +698,11 @@ function disp (this) fmt = args{1}; args(1) = []; for i = 1:numel (args) - if isa (args{i}, 'datetime') + if (isa (args{i}, 'datetime')) args{i} = datestr (args{i}); endif endfor - if isempty (fid) + if (isempty (fid)) fprintf (fmt, args{:}); else fprintf (fid, fmt, args{:}); @@ -727,7 +727,7 @@ function disp (this) ## ## @end deftypefn function out = datestruct (this) - if isempty (this.TimeZone) + if (isempty (this.TimeZone)) local_dnums = this.dnums; else local_dnums = datetime.convertDatenumTimeZone (this.dnums, 'UTC', this.TimeZone); @@ -770,7 +770,7 @@ function disp (this) ## @end deftypefn function out = datenum (this) dnums = this.dnums; - if !isempty (this.TimeZone) && !isequal (this.TimeZone, 'UTC') + if (! isempty (this.TimeZone) && !isequal (this.TimeZone, 'UTC')) dnums = datetime.convertDatenumTimeZone (dnums, 'UTC', this.TimeZone); endif out = dnums; @@ -789,7 +789,7 @@ function disp (this) ## ## @end deftypefn function out = gmtime (this) - if isempty (this) + if (isempty (this)) tm_struct = gmtime (time ()); out = reshape (repmat (tm_struct, [0 0]), size (this)); return @@ -825,7 +825,7 @@ function disp (this) ## ## @end deftypefn function out = localtime (this) - if isempty (this) + if (isempty (this)) tm_struct = localtime (time ()); out = reshape (repmat (tm_struct, [0 0]), size (this)); return @@ -925,7 +925,7 @@ function disp (this) function out = ne (A, B) #NE Not equal. [A, B] = datetime.promote (A, B); - out = A.dnums ~= B.dnums; + out = A.dnums != B.dnums; endfunction ## -*- texinfo -*- @@ -1008,14 +1008,14 @@ function disp (this) B_in = B; # TODO: Maybe support `duration/calendarDuration + datetime` form by just swapping the # arguments. - if !isa (A, 'datetime') + if (! isa (A, 'datetime')) error ('datetime.plus: Expected left-hand side of A + B to be a datetime; got a %s', ... class (A)); endif - if isa (B, 'duration') + if (isa (B, 'duration')) out = A; out.dnums = A.dnums + B.days; - elseif isa (B, 'calendarDuration') + elseif (isa (B, 'calendarDuration')) [A, B] = tblish.internal.chrono.scalarexpand (A, B); out = A; for i = 1:numel (A) @@ -1024,7 +1024,7 @@ function disp (this) out_i = plusScalarCalendarDuration (A_i, B_i); out = asgn(out, i, out_i); endfor - elseif isnumeric (B) + elseif (isnumeric (B)) out = A + duration.ofDays (B); else error ('datetime.plus: Invalid input type: %s', class (B)); @@ -1034,7 +1034,7 @@ function disp (this) function out = plusScalarCalendarDuration (this, dur) ds = datestruct (this); out = this; - if dur.Sign < 0 + if (dur.Sign < 0) ds.Year = ds.Year - dur.Years; ds.Month = ds.Month - dur.Months; ds.Day = ds.Day - dur.Days; @@ -1070,7 +1070,7 @@ function disp (this) ## @end deftypefn function out = minus (A, B) #MINUS Subtraction. - if isa (A, 'datetime') && isa (B, 'datetime') + if (isa (A, 'datetime') && isa (B, 'datetime')) [A, B] = datetime.promote(A, B); out = duration.ofDays (A.dnums - B.dnums); else @@ -1116,7 +1116,7 @@ function disp (this) function out = colon (this, varargin) narginchk (2, 3); - switch nargin + switch (nargin) case 2 limit = varargin{1}; increment = 1; @@ -1124,22 +1124,22 @@ function disp (this) increment = varargin{1}; limit = varargin{2}; endswitch - if isa (increment, 'calendarDuration') + if (isa (increment, 'calendarDuration')) # TODO: Fix this slow, Shlemiel implementation out = this; - while subset (out, numel(out)) < limit + while (subset (out, numel(out)) < limit) next_date = subset (out, numel(out)) + increment; out = [out next_date]; endwhile return endif - if isnumeric (increment) + if (isnumeric (increment)) increment = duration.ofDays (increment); endif - if !isa (increment, 'duration') + if (! isa (increment, 'duration')) error ('increment must be a duration object'); endif - if !isscalar (this) || !isscalar (limit) + if (! isscalar (this) || !isscalar (limit)) error ('base and limit must both be scalar'); endif out = this; @@ -1166,12 +1166,12 @@ function disp (this) function out = linspace (from, to, n) #LINSPACE Linearly-spaced values narginchk (2, 3); - if nargin < 3; n = 100; endif - if isnumeric (from) + if (nargin < 3); n = 100; endif + if (isnumeric (from)) from = datetime.ofDatenum (from); endif [from, to] = datetime.promote (from, to); - if !isscalar (from) || !isscalar (to) + if (! isscalar (from) || !isscalar (to)) error ('Inputs must be scalar'); endif out = from; @@ -1195,7 +1195,7 @@ function disp (this) function out = size (this, dim) #SIZE Size of array. - if nargin == 1 + if (nargin == 1) out = size (this.dnums); else out = size (this.dnums, dim); @@ -1274,7 +1274,7 @@ function disp (this) function [this, nshifts] = shiftdim (this, n) #SHIFTDIM Shift dimensions. - if nargin > 1 + if (nargin > 1) this.dnums = shiftdim (this.dnums, n); else [this.dnums, nshifts] = shiftdim (this.dnums); @@ -1303,7 +1303,7 @@ function disp (this) #SUBSASGN Subscripted assignment. # Chained subscripts - if numel(s) > 1 + if (numel(s) > 1) rhs_in = subsref (this, s(1)); rhs = subsasgn (rhs_in, s(2:end), b); else @@ -1311,7 +1311,7 @@ function disp (this) endif # Base case - switch s(1).type + switch (s(1).type) case '()' this = subsasgnParensPlanar (this, s(1), rhs); #TODO: Correct value of vivified indexes to NaN; right now it's zero. @@ -1326,7 +1326,7 @@ function disp (this) #SUBSREF Subscripted reference. # Base case - switch s(1).type + switch (s(1).type) case '()' out = subsrefParensPlanar (this, s(1)); case '{}' @@ -1336,14 +1336,14 @@ function disp (this) endswitch # Chained reference - if numel (s) > 1 + if (numel (s) > 1) out = subsref (out, s(2:end)); endif endfunction function [out, Indx] = sort (this) #SORT Sort array elements. - if isvector (this) + if (isvector (this)) isRow = isrow (this); this = subset (this, ':'); # NaNs sort stably to end, so handle them separately @@ -1355,10 +1355,10 @@ function disp (this) [~, ix] = sortrows (proxy); out = [subset(nonnans, ix); nans]; Indx = [ixNonNan(ix); find (tfNan)]; - if isRow + if (isRow) out = out'; endif - elseif ismatrix (this) + elseif (ismatrix (this)) out = this; Indx = NaN (size(out)); for iCol = 1:size (this, 2) @@ -1380,19 +1380,19 @@ function disp (this) sz = size (this); nDims = ndims (this); ixs = [{':'} repmat({1}, [1 nDims-1])]; - while true + while (true) col = subset (this, ixs{:}); [sortedCol, sortIx] = sort (col); Indx(ixs{:}) = sortIx; out = asgn (out, ixs, sortedCol); ixs{end} = ixs{end}+1; for iDim=nDims:-1:3 - if ixs{iDim} > sz(iDim) + if (ixs{iDim} > sz(iDim)) ixs{iDim-1} = ixs{iDim-1} + 1; ixs{iDim} = 1; endif endfor - if ixs{2} > sz(2) + if (ixs{2} > sz(2)) break; endif endwhile @@ -1401,7 +1401,7 @@ function disp (this) function [out, Indx] = unique (this, varargin) #UNIQUE Set unique. flags = setdiff (varargin, {'rows'}); - if ismember('rows', varargin) + if (ismember ('rows', varargin)) [~,proxyIx] = unique (this); proxyIx = reshape (proxyIx, size (this)); [~,Indx] = unique (proxyIx, 'rows', flags{:}); @@ -1414,14 +1414,14 @@ function disp (this) nonnans = subset (this, !tfNaN); ixNonnan = find (!tfNaN); keys = proxyKeys (nonnans); - if isa (keys, 'table') + if (isa (keys, 'table')) [~,ix] = unique (keys, flags{:}); else [~,ix] = unique (keys, 'rows', flags{:}); endif out = [subset(nonnans, ix); nans]; Indx = [ixNonnan(ix); find (tfNaN)]; - if isRow + if (isRow) out = out'; endif endif @@ -1429,13 +1429,13 @@ function disp (this) function [out, Indx] = ismember (a, b, varargin) #ISMEMBER True for set member. - if ismember ('rows', varargin) + if (ismember ('rows', varargin)) error ('ismember(..., ''rows'') is unsupported'); endif - if !isa (a, 'datetime') + if (! isa (a, 'datetime')) a = datetime (a); endif - if !isa (b, 'datetime') + if (! isa (b, 'datetime')) b = datetime (b); endif [proxyA, proxyB] = proxyKeys (a, b); @@ -1446,7 +1446,7 @@ function disp (this) function [out, Indx] = setdiff (a, b, varargin) #SETDIFF Set difference. - if ismember ('rows', varargin) + if (ismember ('rows', varargin)) error ('setdiff(..., ''rows'') is unsupported'); endif [tf,~] = ismember (a, b); @@ -1458,7 +1458,7 @@ function disp (this) function [out, ia, ib] = intersect (a, b, varargin) #INTERSECT Set intersection. - if ismember ('rows', varargin) + if (ismember ('rows', varargin)) error ('intersect(..., ''rows'') is unsupported'); endif [proxyA, proxyB] = proxyKeys (a, b); @@ -1468,7 +1468,7 @@ function disp (this) function [out, ia, ib] = union (a, b, varargin) #UNION Set union. - if ismember ('rows', varargin) + if (ismember ('rows', varargin)) error ('union(..., ''rows'') is unsupported'); endif [proxyA, proxyB] = proxyKeys (a, b); @@ -1484,7 +1484,7 @@ function disp (this) function out = subsasgnParensPlanar (this, s, rhs) #SUBSASGNPARENSPLANAR ()-assignment for planar object - if !isa (rhs, 'datetime') + if (! isa (rhs, 'datetime')) rhs = datetime (rhs); endif out = this; @@ -1516,7 +1516,7 @@ function disp (this) # This is what you call internally inside the class instead of doing # ()-indexing references on the LHS, which don't work properly inside # the class because they don't respect the subsasgn() override. - if !iscell (ix) + if (! iscell (ix)) ix = { ix }; endif s.type = '()'; @@ -1566,14 +1566,14 @@ function disp (this) #PROMOTE Promote inputs to be compatible args = varargin; for i = 1:numel (args) - if !isa (args{i}, 'datetime') + if (! isa (args{i}, 'datetime')) args{i} = datetime (args{i}); endif endfor tz0 = args{1}.TimeZone; for i = 2:numel (args) - if !isequal (args{i}.TimeZone, tz0) - if isempty (tz0) || isempty (args{i}.TimeZone) + if (! isequal (args{i}.TimeZone, tz0)) + if (isempty (tz0) || isempty (args{i}.TimeZone)) error('Cannot mix zoned and zoneless datetimes.'); else args{i}.TimeZone = tz0; diff --git a/inst/days.m b/inst/days.m index 1c880a31..27796344 100644 --- a/inst/days.m +++ b/inst/days.m @@ -40,9 +40,9 @@ # # If x is a duration, then returns a double array indicating the number of # days that duration is. - if isnumeric (x) + if (isnumeric (x)) out = duration.ofDays (double (x)); - elseif isa (x, 'duration') + elseif (isa (x, 'duration')) out = x.days; else error ('Invalid input: expected numeric or duration; got %s', class (x)); diff --git a/inst/discretize.m b/inst/discretize.m index b0dd0efa..57828e25 100644 --- a/inst/discretize.m +++ b/inst/discretize.m @@ -44,38 +44,38 @@ display_format = []; category_names = []; [opts, args] = peelOffNameValueOptions (varargin, {'IncludedEdge'}); - if numel (args) >= 1 && isequal (args{end}, 'categorical') + if (numel (args) >= 1 && isequal (args{end}, 'categorical')) do_categorical = true; args(end) = []; endif - if numel (args) >= 2 && isequal (args{end-1}, 'categorical') + if (numel (args) >= 2 && isequal (args{end-1}, 'categorical')) do_categorical = true; categorical_arg = args{end}; - if isa (X, 'datetime') || isa (X, 'duration') && ischar (categorical_arg) + if (isa (X, 'datetime') || isa (X, 'duration') && ischar (categorical_arg)) display_format = categorical_arg; else category_names = cellstr (categorical_arg); endif args(end-1:end) = []; endif - if numel (args) > 1 + if (numel (args) > 1) error ('discretize: too many arguments'); endif value_map = []; - if ! isempty (args) + if (! isempty (args)) value_map = args{i}; endif - if isa (arg1, 'duration') + if (isa (arg1, 'duration')) error ('discretize: duration-valued bin size is not yet implemented. Sorry.'); - elseif isscalar (arg1) + elseif (isscalar (arg1)) mustBeNumeric (arg1); n_bins = arg1; min_x = min (X(:)); max_x = max (X(:)); bin_size = (max_x - min_x) / n_bins; edges = min_x:bin_size:max_x; - if numel (edges) < n_bins + 1 + if (numel (edges) < n_bins + 1) edges(end+1) = max_x; else edges(end) = max_x; @@ -96,23 +96,23 @@ tf = edges(end-1) <= X & X <= edges(end); Y(tf) = n_bins; cat_names{n_bins} = gen_category_name (edges(i_bin), edges(i_bin+1), 1); - if isempty (category_names) + if (isempty (category_names)) category_names = cat_names; endif - if do_categorical + if (do_categorical) codes = Y; Y = categorical.from_codes (codes, category_names, 'Ordinal', true); endif - if nargout > 1 + if (nargout > 1) E = edges; endif endfunction function out = gen_category_name (lo, hi, is_closed_on_right) edge_strs = dispstrs ([lo hi]); - if is_closed_on_right + if (is_closed_on_right) out = sprintf ('[%s, %s)', edge_strs{1}, edge_strs{2}); else out = sprintf ('[%s, %s]', edge_strs{1}, edge_strs{2}); diff --git a/inst/dispstrs.m b/inst/dispstrs.m index 9d99e466..0380e602 100644 --- a/inst/dispstrs.m +++ b/inst/dispstrs.m @@ -34,13 +34,13 @@ ## @end deftypefn function out = dispstrs (x) #DISPSTRS Display strings for arbitrary array - if isnumeric (x) || islogical (x) + if (isnumeric (x) || islogical (x)) out = reshape (strtrim (cellstr (num2str (x(:)))), size (x)); - elseif iscellstr (x) || isa (x, 'string') + elseif (iscellstr (x) || isa (x, 'string')) out = cellstr (x); - elseif isa (x, 'datetime') + elseif (isa (x, 'datetime')) out = datestrs (x); - elseif ischar (x) + elseif (ischar (x)) out = num2cell (x); else out = repmat ({sprintf('1-by-1 %s', class(x))}, size (x)); diff --git a/inst/duration.m b/inst/duration.m index b4f32d2b..b9d8b72e 100644 --- a/inst/duration.m +++ b/inst/duration.m @@ -98,19 +98,19 @@ # Peel off options knownOptions = {'InputFormat','Format'}; opts = struct; - while numel (args) >= 3 && isa (args{end-1}, 'char') ... - && ismember (args{end-1}, knownOptions) + while (numel (args) >= 3 && isa (args{end-1}, 'char') ... + && ismember (args{end-1}, knownOptions)) opts.(args{end-1}) = args{end}; args(end-1:end) = []; endwhile # Handle inputs - switch numel (args) + switch (numel (args)) case 0 return case 1 in = args{1}; - if isnumeric (in) - switch size (in, 2) + if (isnumeric (in)) + switch (size (in, 2)) case 3 [H, MI, S] = deal (in(:,1), in(:,2), in(:,3)); this.days = duration.hms2datenum (H, MI, S, 0); @@ -122,7 +122,7 @@ endswitch else in = cellstr (in); - if isfield (opts, 'InputFormat') + if (isfield (opts, 'InputFormat')) this.days = duration.parseTimeStringsToDatenumWithFormat (in, opts.InputFormat); else this.days = duration.parseTimeStringsToDatenum (in); @@ -130,10 +130,10 @@ endif case 2 # Undocumented calling form for internal use - if !isequal (args{2}, 'Backdoor') + if (! isequal (args{2}, 'Backdoor')) error ('Invalid number if inputs: %d', numel (args)); endif - if !isnumeric (args{1}) + if (! isnumeric (args{1})) error ('Input must be numeric; got a %s', class (args{1})); endif this.days = double (args{1}); @@ -269,7 +269,7 @@ function display (this) #DISPLAY Custom display. in_name = inputname (1); - if !isempty (in_name) + if (! isempty (in_name)) fprintf ('%s =\n', in_name); endif disp (this); @@ -277,7 +277,7 @@ function display (this) function disp (this) #DISP Custom display. - if isempty (this) + if (isempty (this)) fprintf ('Empty %s %s\n', size2str (size (this)), class (this)); return; endif @@ -300,16 +300,16 @@ function disp (this) out = cell (size (this)); for i = 1:numel (this) d = this.days(i); - if isnan (d) + if (isnan (d)) out{i} = 'NaT'; continue endif str = ''; - if d < 0 + if (d < 0) str = [str '-']; d = abs(d); endif - if d > 1 + if (d > 1) str = [str sprintf('%d days ', floor(d))]; d = mod (d,1); endif @@ -323,12 +323,12 @@ function disp (this) x = rem (x, 60); seconds = x; msec = round (fracSec * 1000); - if msec == 1000 + if (msec == 1000) seconds = seconds + 1; msec = 0; endif str = [str sprintf('%02d:%02d:%02d', hours, minutes, seconds)]; - if msec >= 1 + if (msec >= 1) str = [str '.' sprintf('%03d', msec)]; endif out{i} = str; @@ -338,7 +338,7 @@ function disp (this) function out = sprintf(fmt, varargin) args = varargin; for i = 1:numel (args) - if isa (args{i}, 'duration') + if (isa (args{i}, 'duration')) args{i} = dispstr (args{i}); endif endfor @@ -347,7 +347,7 @@ function disp (this) function out = fprintf(varargin) args = varargin; - if isnumeric (args{1}) + if (isnumeric (args{1})) fid = args{1}; args(1) = []; else @@ -356,11 +356,11 @@ function disp (this) fmt = args{1}; args(1) = []; for i = 1:numel (args) - if isa (args{i}, 'duration') + if (isa (args{i}, 'duration')) args{i} = dispstr (args{i}); endif endfor - if isempty (fid) + if (isempty (fid)) fprintf (fmt, args{:}); else fprintf (fid, fmt, args{:}); @@ -403,7 +403,7 @@ function disp (this) function out = ne (A, B) #NE Not equal. [A, B] = duration.promote (A, B); - out = A.days ~= B.days; + out = A.days != B.days; endfunction function out = eq (A, B) @@ -428,10 +428,10 @@ function disp (this) function out = times (A, B) #TIMES Multiplication - if isnumeric (A) + if (isnumeric (A)) out = B; out.days = out.days .* A; - elseif isnumeric (B) + elseif (isnumeric (B)) out = A; out.days = out.days .* B; else @@ -441,10 +441,10 @@ function disp (this) function out = mtimes (A, B) #MTIMES Multiplication - if isnumeric (A) + if (isnumeric (A)) out = B; out.days = out.days * A; - elseif isnumeric (B) + elseif (isnumeric (B)) out = A; out.days = out.days * B; else @@ -454,13 +454,13 @@ function disp (this) function out = rdivide (A, B) #RDIVIDE Element-wise right division - if !isa (A, 'duration') + if (! isa (A, 'duration')) error ('When dividing using duration, the left-hand side must be a duration; got a %s', ... class (A)); endif - if isa (B, 'duration') + if (isa (B, 'duration')) out = A.days ./ B.days; - elseif isa (B, 'double') + elseif (isa (B, 'double')) out = A; out.days = A.days ./ B; else @@ -470,11 +470,11 @@ function disp (this) function out = mrdivide (A, B) #MRDIVIDE Matrix right division - if !isa (A, 'duration') + if (! isa (A, 'duration')) error ('When dividing using duration, the left-hand side must be a duration; got a %s', ... class (A)); endif - if isa (B, 'double') + if (isa (B, 'double')) out = A; out.days = A.days / B; else @@ -484,18 +484,18 @@ function disp (this) function out = plus (A, B) #PLUS Addition - if isa (A, 'datetime') && isa (B, 'duration') + if (isa (A, 'datetime') && isa (B, 'duration')) out = A; out.dnums = out.dnums + B.days; - elseif isa (A, 'duration') && isa (B, 'datetime') + elseif (isa (A, 'duration') && isa (B, 'datetime')) out = B + A; - elseif isa (A, 'duration') && isa (B, 'duration') + elseif (isa (A, 'duration') && isa (B, 'duration')) out = A; out.days = A.days + B.days; - elseif isa (A, 'duration') && isa (B, 'double') + elseif (isa (A, 'duration') && isa (B, 'double')) out = A; out.days = A.days + B; - elseif isa (A, 'double') && isa (B, 'duration') + elseif (isa (A, 'double') && isa (B, 'duration')) out = B + A; endif endfunction @@ -519,7 +519,7 @@ function disp (this) function out = colon (varargin) #COLON Generate range for colon expression narginchk (2, 3); - if nargin == 2; + if (nargin == 2) [from, to] = varargin{:}; increment = 1; else @@ -550,7 +550,7 @@ function disp (this) function out = linspace (A, B, n) #LINSPACE Linearly spaced elements between two values narginchk (2, 3); - if nargin < 3; n = 100; end + if (nargin < 3); n = 100; end [A, B] = duration.promote (A, B); out = A; out.days = linspace (A.days, B.days, n); @@ -559,7 +559,7 @@ function disp (this) methods (Static, Access = private) function out = hms2datenum (H, MI, S, MS) - if nargin < 4; MS = 0; endif + if (nargin < 4); MS = 0; endif [H, MI, S, MS] = deal (double(H), double(MI), double(S), double(MS)); out = (H / 24) + (MI / (24 * 60)) + (S / (24 * 60 * 60)) ... + (MS / (24 * 60 * 60 * 1000)); @@ -572,9 +572,9 @@ function disp (this) strIn = strs{i}; str = strIn; ixDot = find (str == '.'); - if numel (ixDot) > 1 + if (numel (ixDot) > 1) error ('Invalid TimeString: ''%s''', strIn); - elseif !isempty (ixDot) + elseif (! isempty (ixDot)) fractionalSecStr = str(ixDot+1:end); str(ixDot:end) = []; nFracs = str2double (fractionalSecStr); @@ -584,11 +584,11 @@ function disp (this) MS = 0; endif els = strsplit (str, ':'); - if numel (els) == 3 + if (numel (els) == 3) D = 0; [H, MI, S] = deal (str2double (els{1}), str2double (els{2}), ... str2double (els{3})); - elseif numel(els) == 4 + elseif (numel(els) == 4) [D, H, MI ,S] = deal(str2double (els{1}), str2double (els{2}), ... str2double (els{3}), str2double (els{4})); else @@ -620,7 +620,7 @@ function disp (this) function out = size (this, dim) #SIZE Size of array. - if nargin == 1 + if (nargin == 1) out = size (this.days); else out = size (this.days, dim); @@ -704,7 +704,7 @@ function disp (this) function [this, nshifts] = shiftdim (this, n) #SHIFTDIM Shift dimensions. - if nargin > 1 + if (nargin > 1) this.days = shiftdim (this.days, n); else [this.days, nshifts] = shiftdim (this.days); @@ -715,7 +715,7 @@ function disp (this) #CAT Concatenate arrays. args = varargin; for i = 1:numel (args) - if !isa (args{i}, 'duration') + if (! isa (args{i}, 'duration')) args{i} = duration (args{i}); endif endfor @@ -738,7 +738,7 @@ function disp (this) #SUBSASGN Subscripted assignment. # Chained subscripts - if numel (s) > 1 + if (numel (s) > 1) rhs_in = subsref (this, s(1)); rhs = subsasgn (rhs_in, s(2:end), b); else @@ -746,7 +746,7 @@ function disp (this) endif # Base case - switch s(1).type + switch (s(1).type) case '()' this = subsasgnParensPlanar (this, s(1), rhs); case '{}' @@ -760,7 +760,7 @@ function disp (this) #SUBSREF Subscripted reference. # Base case - switch s(1).type + switch (s(1).type) case '()' out = subsrefParensPlanar (this, s(1)); case '{}' @@ -770,14 +770,14 @@ function disp (this) endswitch # Chained reference - if numel(s) > 1 + if (numel (s) > 1) out = subsref (out, s(2:end)); endif endfunction function [out,Indx] = sort (this) #SORT Sort array elements. - if isvector (this) + if (isvector (this)) isRow = isrow (this); this = subset (this, ':'); # NaNs sort stably to end, so handle them separately @@ -789,10 +789,10 @@ function disp (this) [~, ix] = sortrows (proxy); out = [subset(nonnans, ix); nans]; Indx = [ixNonNan(ix); find(tfNan)]; - if isRow + if (isRow) out = out'; endif - elseif ismatrix (this) + elseif (ismatrix (this)) out = this; Indx = NaN (size (out)); for iCol = 1:size(this, 2) @@ -807,29 +807,29 @@ function disp (this) sz = size (this); nDims = ndims (this); ixs = [{':'} repmat({1}, [1 nDims-1])]; - while true + while (true) col = subset (this, ixs{:}); [sortedCol, sortIx] = sort (col); Indx(ixs{:}) = sortIx; out = asgn (out, ixs, sortedCol); ixs{end} = ixs{end}+1; for iDim=nDims:-1:3 - if ixs{iDim} > sz(iDim) + if (ixs{iDim} > sz(iDim)) ixs{iDim-1} = ixs{iDim-1} + 1; ixs{iDim} = 1; endif endfor - if ixs{2} > sz(2) - break; + if (ixs{2} > sz(2)) + break endif endwhile endif endfunction - function [out,Indx] = unique (this, varargin) + function [out, Indx] = unique (this, varargin) #UNIQUE Set unique. flags = setdiff (varargin, {'rows'}); - if ismember ('rows', varargin) + if (ismember ('rows', varargin)) [~, proxyIx] = unique (this); proxyIx = reshape (proxyIx, size (this)); [~, Indx] = unique (proxyIx, 'rows', flags{:}); @@ -842,14 +842,14 @@ function disp (this) nonnans = subset (this, !tfNaN); ixNonnan = find (!tfNaN); keys = proxyKeys (nonnans); - if isa (keys, 'table') + if (isa (keys, 'table')) [~,ix] = unique (keys, flags{:}); else [~,ix] = unique (keys, 'rows', flags{:}); endif out = [subset(nonnans, ix); nans]; Indx = [ixNonnan(ix); find(tfNaN)]; - if isRow + if (isRow) out = out'; endif endif @@ -857,13 +857,13 @@ function disp (this) function [out, Indx] = ismember (a, b, varargin) #ISMEMBER True for set member. - if ismember ('rows', varargin) + if (ismember ('rows', varargin)) error ('ismember(..., ''rows'') is unsupported'); endif - if !isa (a, 'duration') + if (! isa (a, 'duration')) a = duration (a); endif - if !isa (b, 'duration') + if (! isa (b, 'duration')) b = duration (b); endif [proxyA, proxyB] = proxyKeys (a, b); @@ -874,7 +874,7 @@ function disp (this) function [out,Indx] = setdiff (a, b, varargin) #SETDIFF Set difference. - if ismember ('rows', varargin) + if (ismember ('rows', varargin)) error ('setdiff(..., ''rows'') is unsupported'); endif [tf,~] = ismember (a, b); @@ -886,7 +886,7 @@ function disp (this) function [out, ia, ib] = intersect (a, b, varargin) #INTERSECT Set intersection. - if ismember ('rows', varargin) + if (ismember ('rows', varargin)) error ('intersect(..., ''rows'') is unsupported'); endif [proxyA, proxyB] = proxyKeys (a, b); @@ -896,7 +896,7 @@ function disp (this) function [out, ia, ib] = union (a, b, varargin) #UNION Set union. - if ismember ('rows', varargin) + if (ismember ('rows', varargin)) error ('union(..., ''rows'') is unsupported'); endif [proxyA, proxyB] = proxyKeys (a, b); @@ -912,7 +912,7 @@ function disp (this) function out = subsasgnParensPlanar (this, s, rhs) #SUBSASGNPARENSPLANAR ()-assignment for planar object - if !isa (rhs, 'duration') + if (! isa (rhs, 'duration')) rhs = duration (rhs); endif out = this; @@ -944,7 +944,7 @@ function disp (this) # This is what you call internally inside the class instead of doing # ()-indexing references on the LHS, which don't work properly inside # the class because they don't respect the subsasgn() override. - if !iscell (ix) + if (! iscell (ix)) ix = { ix }; endif s.type = '()'; @@ -959,10 +959,10 @@ function disp (this) #PROMOTE Promote inputs to be compatible args = varargin; for i = 1:numel(args) - if !isa (args{i}, 'duration') + if (! isa (args{i}, 'duration')) # Sigh. We can't use a simple constructor call because of its weird # signature. - if isnumeric (args{i}) + if (isnumeric (args{i})) args{i} = duration.ofDays (args{i}); else args{i} = duration (args{i}); diff --git a/inst/examples/tblish_ex_01_suppliers_parts.m b/inst/examples/tblish_ex_01_suppliers_parts.m index 1df66775..b3b50be8 100644 --- a/inst/examples/tblish_ex_01_suppliers_parts.m +++ b/inst/examples/tblish_ex_01_suppliers_parts.m @@ -3,23 +3,23 @@ # The Suppliers-Parts database is defined over in +tblish/+examples -[s,p,sp] = tblish.examples.SpDb; +[s, p, sp] = tblish.examples.SpDb; # Display one of the tables -fprintf('\nTable s:\n'); +fprintf ('\nTable s:\n'); prettyprint (s) # Get the suppliers just in London london_suppliers = s(strcmp (s.City, 'London'),:) -fprintf('\nSuppliers in London:\n') +fprintf ('\nSuppliers in London:\n') prettyprint (london_suppliers) # Suppliers in Paris with a status of 20 or greater paris = s(strcmp (s.City, 'Paris') & s.Status >= 20,:) -fprintf('\nParis suppliers with status >= 20:\n') +fprintf ('\nParis suppliers with status >= 20:\n') prettyprint (paris) # Join the tables up so we can do aggregate queries @@ -29,8 +29,8 @@ s2 = renamevars (s, {'City' 'SupplierCity'}) p2 = renamevars (p, {'City' 'PartCity'}); # Join all the tables -j = innerjoin(innerjoin(sp, s2), p2); -fprintf('\nJoined tables:\n') +j = innerjoin (innerjoin (sp, s2), p2); +fprintf ('\nJoined tables:\n') prettyprint (j) # Calculate the total weight of deliveries diff --git a/inst/hours.m b/inst/hours.m index 560297ff..604b11d3 100644 --- a/inst/hours.m +++ b/inst/hours.m @@ -35,7 +35,7 @@ # If input is numeric, returns a @duration array that is that many hours long. # # If input is a duration, converts the duration to a number of hours. - if isnumeric (x) + if (isnumeric (x)) out = duration.ofDays (double (x) / 24); else error ('Invalid input: expected numeric or duration; got %s', class (x)); diff --git a/inst/iscalendarduration.m b/inst/iscalendarduration.m index 00e46565..8c3e0951 100644 --- a/inst/iscalendarduration.m +++ b/inst/iscalendarduration.m @@ -33,11 +33,11 @@ #ISCALENDARDURATION True if input is a calendar duration array # Developer note: see istable for an explanation of this logic. - if isa (x, 'calendarDuration') + if (isa (x, 'calendarDuration')) out = true; - elseif isobject (x) + elseif (isobject (x)) # Respect iscalendarduration methods on classes. - if ismember ('iscalendarduration', methods (x)) + if (ismember ('iscalendarduration', methods (x))) out = iscalendarduration (x); else out = false; diff --git a/inst/iscategorical.m b/inst/iscategorical.m index bbabe376..99dd9c5e 100644 --- a/inst/iscategorical.m +++ b/inst/iscategorical.m @@ -31,11 +31,11 @@ function out = iscategorical (x) # Developer note: see istable for an explanation of this logic. - if isa (x, 'categorical') + if (isa (x, 'categorical')) out = true; - elseif isobject (x) + elseif (isobject (x)) # Respect iscategorical methods on classes. - if ismember ('iscategorical', methods (x)) + if (ismember ('iscategorical', methods (x))) out = iscategorical (x); else out = false; diff --git a/inst/isdatetime.m b/inst/isdatetime.m index 0d76a3de..ae361ed7 100644 --- a/inst/isdatetime.m +++ b/inst/isdatetime.m @@ -33,11 +33,11 @@ #ISDATETIME True if input is a datetime array. # Developer note: see istable for an explanation of this logic. - if isa (x, 'datetime') + if (isa (x, 'datetime')) out = true; - elseif isobject (x) + elseif (isobject (x)) # Respect isdatetime methods on classes. - if ismember ('isdatetime', methods (x)) + if (ismember ('isdatetime', methods (x))) out = isdatetime (x); else out = false; diff --git a/inst/isduration.m b/inst/isduration.m index 0e02d73c..0b997dd3 100644 --- a/inst/isduration.m +++ b/inst/isduration.m @@ -33,11 +33,11 @@ #ISDURATION True if input is a duration array # Developer note: see istable for an explanation of this logic. - if isa (x, 'duration') + if (isa (x, 'duration')) out = true; - elseif isobject (x) + elseif (isobject (x)) # Respect isduration methods on classes. - if ismember ('isduration', methods (x)) + if (ismember ('isduration', methods (x))) out = isduration (x); else out = false; diff --git a/inst/isnanny.m b/inst/isnanny.m index fbd80204..9fcd4fe6 100644 --- a/inst/isnanny.m +++ b/inst/isnanny.m @@ -42,17 +42,17 @@ ## ## @end deftypefn function out = isnanny (x) - if isnumeric (x) + if (isnumeric (x)) out = isnan (x); - elseif isa (x, 'datetime') + elseif (isa (x, 'datetime')) out = isnat (x); - elseif isa (x, 'duration') || isa (x, 'calendarDuration') + elseif (isa (x, 'duration') || isa (x, 'calendarDuration')) out = isnan (x); - elseif isobject (x) + elseif (isobject (x)) # Static method invocation (instead of string-based/feval) for speed - if ismethod (x, 'ismissing') + if (ismethod (x, 'ismissing')) out = ismissing (x); - elseif ismethod (x, 'isnan') + elseif (ismethod (x, 'isnan')) out = isnan (x); else out = false (size (x)); diff --git a/inst/istable.m b/inst/istable.m index 3a570a8d..b75565d8 100644 --- a/inst/istable.m +++ b/inst/istable.m @@ -43,17 +43,17 @@ function out = istable (x) #ISTABLE True for table arrays or table-like arrays. - if isa (x, 'table') + if (isa (x, 'table')) # Main case: table arrays are tables. # This is actually redundant with the generic isobject/method test below, # but written separately for readability. out = true; - elseif isobject (x) + elseif (isobject (x)) # Respect istable methods on classes. Normally, those methods would "grab" # this call. We check for it here so that these method overrides are respected # even if this istable function was called through a function handle or # similar mechanism, bypassing the regular method dispatch mechanism. - if ismember ('istable', methods (x)) + if (ismember ('istable', methods (x))) out = istable (x); else out = false; diff --git a/inst/localdate.m b/inst/localdate.m index f2b2078d..5e389c5d 100644 --- a/inst/localdate.m +++ b/inst/localdate.m @@ -93,30 +93,30 @@ args = varargin; knownOptions = {'Format','InputFormat','Locale','PivotYear'}; opts = struct; - while numel (args) >= 3 && isa (args{end-1}, 'char') ... - && ismember (args{end-1}, knownOptions) + while (numel (args) >= 3 && isa (args{end-1}, 'char') ... + && ismember (args{end-1}, knownOptions)) opts.(args{end-1}) = args{end}; args(end-1:end) = []; endwhile # Handle inputs - switch numel (args) + switch (numel (args)) case 0 dnums = floor (now); case 1 x = args{1}; - if isnumeric (x) + if (isnumeric (x)) # Convert datenums mustBeIntOrNanOrInf (x, 'input'); dnums = double (x); - elseif ischar (x) || iscellstr (x) || isa (x, 'string') + elseif (ischar (x) || iscellstr (x) || isa (x, 'string')) x = cellstr (x); tfRelative = ismember (x, {'today','tomorrow','yesterday','now'}); - if all (tfRelative) - if !isscalar (x) + if (all (tfRelative)) + if (! isscalar (x)) error ('Multiple arguments not allowed for relativeDay format'); endif - switch x{1} + switch (x{1}) case 'yesterday' dnums = floor (now) - 1; case 'today' @@ -129,37 +129,37 @@ else # They're datestrs # TODO: Support Locale option - if isfield (opts, 'Locale') + if (isfield (opts, 'Locale')) error ('Locale option is unimplemented'); endif # TODO: Support PivotYear option - if isfield (opts, 'PivotYear') + if (isfield (opts, 'PivotYear')) error ('PivotYear option is unimplemented'); endif - if isfield (opts, 'InputFormat') + if (isfield (opts, 'InputFormat')) dnums = datenum (x, opts.InputFormat); else dnums = datenum (x); endif tf = isIntOrNanOrInf (dnums); - if ! all (tf) + if (! all (tf)) error ('localdate: input datestrs may not have nonzero time-of-day parts'); endif dnums = reshape (dnums, size (x)); endif - elseif isstruct (x) + elseif (isstruct (x)) error ('localdate: struct to localdate conversion has not been spec''ed or implemented yet'); elseif ismember (class (x), {'java.util.Date', 'java.util.Date[]', 'java.time.TemporalAccessor', ... 'java.time.TemporalAccessor[]'}) error ('localdate: Java date conversion is not implemented yet. Sorry.'); - elseif isa (x, 'datetime') + elseif (isa (x, 'datetime')) dnums = datenum (x); else error ('localdate: Invalid input type: %s', class (x)); endif case 2 # Undocumented calling form for Tablicious's internal use - if !isequal (args{2}, 'Backdoor') + if (! isequal (args{2}, 'Backdoor')) error ('Invalid number of inputs (excluding options): %d', numel (args)); endif dnums = args{1}; @@ -215,13 +215,13 @@ dvec(:,1) = dstruct.Year(:); dvec(:,2) = dstruct.Month(:); dvec(:,3) = dstruct.Day(:); - if isfield (dstruct, 'Hour') + if (isfield (dstruct, 'Hour')) mustBeIntOrNanOrInf (dstruct.Hour, 'Hour field of datestruct'); endif - if isfield (dstruct, 'Hour') + if (isfield (dstruct, 'Hour')) mustBeIntOrNanOrInf (dstruct.Minute, 'Minute field of datestruct'); endif - if isfield (dstruct, 'Hour') + if (isfield (dstruct, 'Hour')) mustBeIntOrNanOrInf (dstruct.Second, 'Second field of datestruct'); endif dvec(:,4) = 0; @@ -318,13 +318,13 @@ function validate (this) endfunction function out = week (this) - error('week() is unimplemented'); + error ('week() is unimplemented'); endfunction function display (this) #DISPLAY Custom display. in_name = inputname (1); - if !isempty (in_name) + if (! isempty (in_name)) fprintf ('%s =\n', in_name); endif disp (this); @@ -332,9 +332,9 @@ function display (this) function disp (this) #DISP Custom display. - if isempty (this) + if (isempty (this)) fprintf ('Empty %s %s\n', size2str (size (this)), class (this)); - elseif isscalar (this) + elseif (isscalar (this)) str = dispstrs (this); str = str{1}; fprintf (' %s\n', str); @@ -360,24 +360,24 @@ function disp (this) local_dnums = this.dnums; tfNaN = isnan (local_dnums); out(tfNaN) = {'NaT'}; - if any(!tfNaN(:)) + if (any (!tfNaN(:))) out(!tfNaN) = cellstr (datestr (local_dnums(!tfNaN))); endif endfunction - function out = sprintf(fmt, varargin) + function out = sprintf (fmt, varargin) args = varargin; for i = 1:numel (args) - if isa (args{i}, 'localdate') + if (isa (args{i}, 'localdate')) args{i} = datestr (args{i}); endif endfor out = sprintf (fmt, args{:}); endfunction - function out = fprintf(varargin) + function out = fprintf (varargin) args = varargin; - if isnumeric (args{1}) + if (isnumeric (args{1})) fid = args{1}; args(1) = []; else @@ -386,11 +386,11 @@ function disp (this) fmt = args{1}; args(1) = []; for i = 1:numel (args) - if isa (args{i}, 'localdate') + if (isa (args{i}, 'localdate')) args{i} = datestr (args{i}); endif endfor - if isempty (fid) + if (isempty (fid)) fprintf (fmt, args{:}); else fprintf (fid, fmt, args{:}); @@ -551,7 +551,7 @@ function disp (this) function out = ne (A, B) #NE Not equal. [A, B] = localdate.promote (A, B); - out = A.dnums ~= B.dnums; + out = A.dnums != B.dnums; endfunction function out = eq (A, B) @@ -576,22 +576,22 @@ function disp (this) function out = plus (this, b) mustBeA (this, 'localdate'); - if isnumeric (b) - if ! all (b == floor (b)) + if (isnumeric (b)) + if (! all (b == floor (b))) error('Numeric addends must be integer-valued'); endif b = duration.ofDays (b); endif mustBeScalar (b); - if isa (b, 'duration') + if (isa (b, 'duration')) days = b.days; - if days ~= floor (days) + if (days != floor (days)) error ('Duration addends must be whole-day valued'); endif out = this; out.dnums = this.dnums + days; - elseif isa (b, 'calendarDuration') - if ! all (b.Time == 0) + elseif (isa (b, 'calendarDuration')) + if (! all (b.Time == 0)) error('calendarDuration addends may not have non-zero Time components'); endif year = this.Year + b.Years; @@ -599,14 +599,15 @@ function disp (this) day = this.Day + b.Days; out = localdate (year, month, day); else + error ('unsupported input type: %s', class (b)) endif endfunction function out = minus (a, b) - if ! isa (a, 'localdate') + if (! isa (a, 'localdate')) a = localdate (a); endif - if ! isa (b, 'localdate') + if (! isa (b, 'localdate')) b = localdate (b); endif delta = a.dnums - b.dnums; @@ -627,7 +628,7 @@ function disp (this) function out = size (this, dim) #SIZE Size of array. - if nargin == 1 + if (nargin == 1) out = size (this.dnums); else out = size (this.dnums, dim); @@ -706,7 +707,7 @@ function disp (this) function [this, nshifts] = shiftdim (this, n) #SHIFTDIM Shift dimensions. - if nargin > 1 + if (nargin > 1) this.dnums = shiftdim (this.dnums, n); else [this.dnums, nshifts] = shiftdim (this.dnums); @@ -735,7 +736,7 @@ function disp (this) #SUBSASGN Subscripted assignment. # Chained subscripts - if numel(s) > 1 + if (numel(s) > 1) rhs_in = subsref (this, s(1)); rhs = subsasgn (rhs_in, s(2:end), b); else @@ -743,7 +744,7 @@ function disp (this) endif # Base case - switch s(1).type + switch (s(1).type) case '()' this = subsasgnParensPlanar (this, s(1), rhs); #TODO: Correct value of vivified indexes to NaN; right now it's zero. @@ -758,7 +759,7 @@ function disp (this) #SUBSREF Subscripted reference. # Base case - switch s(1).type + switch (s(1).type) case '()' out = subsrefParensPlanar (this, s(1)); case '{}' @@ -787,10 +788,10 @@ function disp (this) [~, ix] = sortrows (proxy); out = [subset(nonnans, ix); nans]; Indx = [ixNonNan(ix); find (tfNan)]; - if isRow + if (isRow) out = out'; endif - elseif ismatrix (this) + elseif (ismatrix (this)) out = this; Indx = NaN (size(out)); for iCol = 1:size (this, 2) @@ -812,20 +813,20 @@ function disp (this) sz = size (this); nDims = ndims (this); ixs = [{':'} repmat({1}, [1 nDims-1])]; - while true + while (true) col = subset (this, ixs{:}); [sortedCol, sortIx] = sort (col); Indx(ixs{:}) = sortIx; out = asgn (out, ixs, sortedCol); ixs{end} = ixs{end}+1; for iDim=nDims:-1:3 - if ixs{iDim} > sz(iDim) + if (ixs{iDim} > sz(iDim)) ixs{iDim-1} = ixs{iDim-1} + 1; ixs{iDim} = 1; endif endfor - if ixs{2} > sz(2) - break; + if (ixs{2} > sz(2)) + break endif endwhile endfunction @@ -833,7 +834,7 @@ function disp (this) function [out, Indx] = unique (this, varargin) #UNIQUE Set unique. flags = setdiff (varargin, {'rows'}); - if ismember('rows', varargin) + if (ismember('rows', varargin)) [~,proxyIx] = unique (this); proxyIx = reshape (proxyIx, size (this)); [~,Indx] = unique (proxyIx, 'rows', flags{:}); @@ -846,14 +847,14 @@ function disp (this) nonnans = subset (this, !tfNaN); ixNonnan = find (!tfNaN); keys = proxyKeys (nonnans); - if isa (keys, 'table') + if (isa (keys, 'table')) [~,ix] = unique (keys, flags{:}); else [~,ix] = unique (keys, 'rows', flags{:}); endif out = [subset(nonnans, ix); nans]; Indx = [ixNonnan(ix); find (tfNaN)]; - if isRow + if (isRow) out = out'; endif endif @@ -861,13 +862,13 @@ function disp (this) function [out, Indx] = ismember (a, b, varargin) #ISMEMBER True for set member. - if ismember ('rows', varargin) + if (ismember ('rows', varargin)) error ('ismember(..., ''rows'') is unsupported'); endif - if !isa (a, 'localdate') + if (! isa (a, 'localdate')) a = localdate (a); endif - if !isa (b, 'localdate') + if (! isa (b, 'localdate')) b = localdate (b); endif [proxyA, proxyB] = proxyKeys (a, b); @@ -878,7 +879,7 @@ function disp (this) function [out, Indx] = setdiff (a, b, varargin) #SETDIFF Set difference. - if ismember ('rows', varargin) + if (ismember ('rows', varargin)) error ('setdiff(..., ''rows'') is unsupported'); endif [tf,~] = ismember (a, b); @@ -890,7 +891,7 @@ function disp (this) function [out, ia, ib] = intersect (a, b, varargin) #INTERSECT Set intersection. - if ismember ('rows', varargin) + if (ismember ('rows', varargin)) error ('intersect(..., ''rows'') is unsupported'); endif [proxyA, proxyB] = proxyKeys (a, b); @@ -900,7 +901,7 @@ function disp (this) function [out, ia, ib] = union (a, b, varargin) #UNION Set union. - if ismember ('rows', varargin) + if (ismember ('rows', varargin)) error ('union(..., ''rows'') is unsupported'); endif [proxyA, proxyB] = proxyKeys (a, b); @@ -916,7 +917,7 @@ function disp (this) function out = subsasgnParensPlanar (this, s, rhs) #SUBSASGNPARENSPLANAR ()-assignment for planar object - if !isa (rhs, 'localdate') + if (! isa (rhs, 'localdate')) rhs = localdate (rhs); endif out = this; @@ -932,7 +933,7 @@ function disp (this) function out = parensRef (this, varargin) #PARENSREF ()-indexing, for this class's internal use - out = subsrefParensPlanar(this, struct ('subs', {varargin})); + out = subsrefParensPlanar (this, struct ('subs', {varargin})); endfunction function out = subset (this, varargin) @@ -948,7 +949,7 @@ function disp (this) # This is what you call internally inside the class instead of doing # ()-indexing references on the LHS, which don't work properly inside # the class because they don't respect the subsasgn() override. - if !iscell (ix) + if (! iscell (ix)) ix = { ix }; endif s.type = '()'; @@ -970,7 +971,7 @@ function disp (this) #PROMOTE Promote inputs to be compatible args = varargin; for i = 1:numel (args) - if !isa (args{i}, 'localdate') + if (! isa (args{i}, 'localdate')) args{i} = localdate (args{i}); endif endfor @@ -988,14 +989,14 @@ function disp (this) endfunction function mustBeNumeric (x, label) - if nargin < 2; label = []; endif - if isnumeric (x) + if (nargin < 2); label = []; endif + if (isnumeric (x)) return endif - if isempty (label) + if (isempty (label)) label = inputname (1); endif - if isempty (label) + if (isempty (label)) label = "input"; endif error ("localdate: %s must be numeric; but got a %s", ... @@ -1003,23 +1004,23 @@ function mustBeNumeric (x, label) endfunction function x = mustBeIntOrNanOrInf (x, label) - if nargin < 2; label = []; endif - if isinteger (x) || islogical (x) + if (nargin < 2); label = []; endif + if (isinteger (x) || islogical (x)) return endif but = []; - if ! isnumeric (x) + if (! isnumeric (x)) but = sprintf ("it was non-numeric (got a %s)", class (x)); - elseif ! isreal (x) + elseif (! isreal (x)) but = "it was complex"; - elseif ! all (floor (x) == x) + elseif (! all (floor (x) == x)) but = "it had fractional values in some elements"; endif - if ! isempty (but) - if isempty (label) + if (! isempty (but)) + if (isempty (label)) label = inputname (1); endif - if isempty (label) + if (isempty (label)) label = "input"; endif error ("localdate: %s must be integer-valued; but %s", ... diff --git a/inst/milliseconds.m b/inst/milliseconds.m index 1cf66d62..de6aa644 100644 --- a/inst/milliseconds.m +++ b/inst/milliseconds.m @@ -36,7 +36,7 @@ # If input is numeric, returns a @duration array that is that many milliseconds long. # # If input is a duration, converts the duration to a number of milliseconds. - if isnumeric (x) + if (isnumeric (x)) out = duration.ofDays (double (x) / (24 * 60 * 60 * 1000)); else error ('Invalid input: expected numeric or duration; got %s', class (x)); diff --git a/inst/minutes.m b/inst/minutes.m index 3d684319..e217f430 100644 --- a/inst/minutes.m +++ b/inst/minutes.m @@ -29,7 +29,7 @@ # If input is numeric, returns a @duration array that is that many minutes long. # # If input is a duration, converts the duration to a number of minutes. - if isnumeric (x) + if (isnumeric (x)) out = duration.ofDays (double(x) / (24 * 60)); else error ('Invalid input: expected numeric or duration; got %s', class (x)); diff --git a/inst/missing.m b/inst/missing.m index 34661163..c4a7c7cd 100644 --- a/inst/missing.m +++ b/inst/missing.m @@ -65,7 +65,7 @@ function display (this) #DISPLAY Custom display. in_name = inputname (1); - if !isempty (in_name) + if (! isempty (in_name)) fprintf ('%s =\n', in_name); endif disp (this); @@ -76,7 +76,7 @@ function disp (this) endfunction function out = dispstr (this) - if isscalar (this) + if (isscalar (this)) out = ''; else out = sprintf ('%s ', size2str (size (this))); @@ -424,7 +424,7 @@ function disp (this) #SUBSASGN Subscripted assignment. # Chained subscripts - if numel(s) > 1 + if (numel(s) > 1) rhs_in = subsref(this, s(1)); rhs = subsasgn(rhs_in, s(2:end), b); else @@ -432,7 +432,7 @@ function disp (this) endif # Base case - switch s(1).type + switch (s(1).type) case '()' this = subsasgnParensPlanar(this, s(1), rhs); case '{}' @@ -446,7 +446,7 @@ function disp (this) #SUBSREF Subscripted reference. # Base case - switch s(1).type + switch (s(1).type) case '()' varargout = { subsrefParensPlanar(this, s(1)) }; case '{}' @@ -458,7 +458,7 @@ function disp (this) endswitch # Chained reference - if numel (s) > 1 + if (numel (s) > 1) out = subsref (out, s(2:end)); endif endfunction @@ -469,7 +469,7 @@ function disp (this) function this = subsasgnParensPlanar (this, s, rhs) #SUBSASGNPARENSPLANAR ()-assignment for planar object - if !isa (rhs, 'missing') + if (! isa (rhs, 'missing')) rhs = missing (rhs); endif this.data(s.subs{:}) = rhs.data; @@ -499,7 +499,7 @@ function disp (this) # This is what you call internally inside the class instead of doing # ()-indexing references on the LHS, which don't work properly inside # the class because they don't respect the subsasgn() override. - if !iscell(ix) + if (! iscell(ix)) ix = { ix }; endif s.type = '()'; @@ -516,17 +516,17 @@ function disp (this) # This will become private before tblish.table release 1.0. found_type = []; for i = 1:numel (args) - if isa (args{i}, 'missing') + if (isa (args{i}, 'missing')) continue - elseif isnumeric (args{i}) || isa (args{i}, 'duration') ... - || isa (args{i}, 'calendarDuration') + elseif (isnumeric (args{i}) || isa (args{i}, 'duration') ... + || isa (args{i}, 'calendarDuration')) # These all take NaNs. found_type = 'numeric'; - elseif iscell (args{i}) + elseif (iscell (args{i})) found_type = 'cell'; - elseif ischar (args{i}) + elseif (ischar (args{i})) found_type = 'char'; - elseif isa (args{i}, 'datetime') + elseif (isa (args{i}, 'datetime')) found_type = 'datetime'; else error ('missing:InvalidInput', ['missing: Unsupported type: %s. ' ... @@ -536,8 +536,8 @@ function disp (this) endfor out = args; for i = 1:numel (args) - if isa (args{i}, 'missing') - switch found_type + if (isa (args{i}, 'missing')) + switch (found_type) case 'numeric' out{i} = NaN (size (args{i})); case 'cell' @@ -553,11 +553,12 @@ function disp (this) function out = size_scalar_expand (A, B) #SIZE_SCALAR_EXPAND Internal implementation method - if isscalar (A) + if (isscalar (A)) out = size (B); else out = size (A); endif endfunction endmethods + endclassdef diff --git a/inst/pp.m b/inst/pp.m index 59416007..47aad1b3 100644 --- a/inst/pp.m +++ b/inst/pp.m @@ -28,7 +28,7 @@ ## This is so you can conveniently run it from the command line. ## ## @end deftypefn -function pp(varargin) +function pp (varargin) #PP Alias for prettyprint, for debugging # # pp (x) @@ -45,18 +45,18 @@ function pp(varargin) show_label = nargin > 1; for i = 1:numel (varargin) arg = varargin{i}; - if ischar (arg) + if (ischar (arg)) label = arg; value = evalin ("caller", arg); else value = arg; label = inputname (i); - if isempty (label) + if (isempty (label)) label = sprintf ("Input %d", i); endif endif - if show_label + if (show_label) fprintf ("%s:\n", label); endif prettyprint (value); diff --git a/inst/private/format_dispstr_array.m b/inst/private/format_dispstr_array.m index d650c8c7..4d5f94bf 100644 --- a/inst/private/format_dispstr_array.m +++ b/inst/private/format_dispstr_array.m @@ -19,7 +19,7 @@ function out = format_dispstr_array (strs) #FORMAT_DISPSTR_ARRAY Format an array of strings as a matrix display - if ismatrix (strs) + if (ismatrix (strs)) out = prettyprint_matrix (strs); else sz = size (strs); @@ -40,14 +40,14 @@ endfor out = strjoin (chunks, '\n'); endif - if nargout == 0 + if (nargout == 0) disp (out); - clear out; + clear out endif endfunction function out = prettyprint_matrix (strs) - if !ismatrix (strs) + if (! ismatrix (strs)) error ('Input must be matrix; got %d-D', ndims (strs)); endif lens = cellfun ('prodofsize', strs); diff --git a/inst/private/intersect_stable.m b/inst/private/intersect_stable.m index 58097b5b..5e1ea896 100644 --- a/inst/private/intersect_stable.m +++ b/inst/private/intersect_stable.m @@ -19,7 +19,7 @@ [tf, indx] = ismember (A, B); out = A(tf); [uOut, ix2] = unique (out); - if numel (uOut) < numel (out) + if (numel (uOut) < numel (out)) ixDup = 1:numel (out); ixDup(ix2) = []; out(ixDup) = []; diff --git a/inst/private/mycombvec.m b/inst/private/mycombvec.m index e2949641..b3cde042 100644 --- a/inst/private/mycombvec.m +++ b/inst/private/mycombvec.m @@ -20,10 +20,10 @@ #MYCOMBVEC All combinations of values from vectors # # This is similar to Matlab's combvec, but has a different signature. - if !iscell (vecs) + if (! iscell (vecs)) error ('Input vecs must be cell'); endif - switch numel (vecs) + switch (numel (vecs)) case 0 error ('Must supply at least one input vector'); case 1 diff --git a/inst/private/peelOffNameValueOptions.m b/inst/private/peelOffNameValueOptions.m index ede7acd6..da5d0ddb 100644 --- a/inst/private/peelOffNameValueOptions.m +++ b/inst/private/peelOffNameValueOptions.m @@ -24,7 +24,7 @@ # * peeldArgs: a cell vector of the arguments that were peeled off. opts = struct; peeledArgs = {}; - while numel (args) >= 2 && ischar (args{end-1}) && ismember (args{end-1}, knownOpts) + while (numel (args) >= 2 && ischar (args{end-1}) && ismember (args{end-1}, knownOpts)) peeledArgs = [peeledArgs args(end-1:end)]; opts.(args{end-1}) = args{end}; args(end-1:end) = []; diff --git a/inst/private/prettyprint_array.m b/inst/private/prettyprint_array.m index f81c0d47..aa87bf52 100644 --- a/inst/private/prettyprint_array.m +++ b/inst/private/prettyprint_array.m @@ -23,7 +23,7 @@ # # strs (cellstr) is an array of display strings of any size. -if ismatrix (strs) +if (ismatrix (strs)) out = prettyprint_matrix (strs); else sz = size (strs); @@ -44,23 +44,23 @@ endfor out = strjoin (chunks, '\n'); endif -if nargout == 0 +if (nargout == 0) disp (out); - clear out; + clear out endif endfunction function out = prettyprint_matrix (strs) -if !ismatrix (strs) +if (! ismatrix (strs)) error ('Input must be matrix; got %d-D', ndims (strs)); endif lens = cellfun ('prodofsize', strs); widths = max (lens); formats = sprintfv ('%%%ds', widths); -format = strjoin (formats, ' '); +fmt = strjoin (formats, ' '); lines = cell (size (strs,1), 1); for i = 1:size (strs, 1) - lines{i} = sprintf (format, strs{i,:}); + lines{i} = sprintf (fmt, strs{i,:}); endfor out = strjoin (lines, '\n'); endfunction diff --git a/inst/private/sprintfv.m b/inst/private/sprintfv.m index 637e7a16..842e8b05 100644 --- a/inst/private/sprintfv.m +++ b/inst/private/sprintfv.m @@ -16,10 +16,10 @@ ## along with Octave; see the file COPYING. If not, see ## . -function out = sprintfv (format, varargin) +function out = sprintfv (fmt, varargin) #SPRINTFV "Vectorized" sprintf # -# out = sprintfv (format, varargin) +# out = sprintfv (fmt, varargin) # # SPRINTFV is an array-oriented form of sprintf that applies a format to array # inputs and produces a cellstr. @@ -32,20 +32,20 @@ args = varargin; sz = []; for i = 1:numel (args) - if ischar (args{i}) + if (ischar (args{i})) args{i} = { args{i} }; %#ok endif - if !isscalar (args{i}) - if isempty (sz) + if (! isscalar (args{i})) + if (isempty (sz)) sz = size (args{i}); else - if !isequal (sz, size (args{i})) + if (! isequal (sz, size (args{i}))) error ('Inconsistent dimensions in inputs'); endif endif endif endfor - if isempty (sz) + if (isempty (sz)) sz = [1 1]; endif @@ -53,18 +53,18 @@ for i = 1:numel (out) theseArgs = cell (size (args)); for iArg = 1:numel (args) - if isscalar (args{iArg}) + if (isscalar (args{iArg})) ix_i = 1; else ix_i = i; endif - if iscell (args{iArg}) + if (iscell (args{iArg})) theseArgs{iArg} = args{iArg}{ix_i}; else theseArgs{iArg} = args{iArg}(ix_i); endif endfor - out{i} = sprintf (format, theseArgs{:}); + out{i} = sprintf (fmt, theseArgs{:}); endfor endfunction diff --git a/inst/proxykeysForMatrixes.m b/inst/proxykeysForMatrixes.m index 283a13fc..4d3a70a2 100644 --- a/inst/proxykeysForMatrixes.m +++ b/inst/proxykeysForMatrixes.m @@ -88,21 +88,21 @@ # Input handling / conversion - if nargin == 1 + if (nargin == 1) pkA = proxykeysForOneMatrix (A); return endif - if !isequal (class (A), class (B)) + if (! isequal (class (A), class (B))) [origA, origB] = deal (A, B); [A, B] = widenTypesForProxyKeys (A, B); - if !isequal (class (A), class (B)) + if (! isequal (class (A), class (B))) error ("proxykeysForMatrixes: Could not convert %s and %s to compatible types", ... class (origA), class (origB)); endif endif - if size (A, 2) != size (B, 2) + if (size (A, 2) != size (B, 2)) error ("proxykeysForMatrixes: Inputs must have same number of columns; got %d and %d", ... size (A, 2), size (B, 2)); endif @@ -111,13 +111,13 @@ # Special-case type optimizations widenableToDoubleIntTypes = {'uint8' 'int8' 'uint16' 'int16' 'uint32' 'int32'}; - if isa (A, 'double') + if (isa (A, 'double')) pkA = A; pkB = B; - elseif isa (A, 'single') + elseif (isa (A, 'single')) pkA = double (A); pkB = double (B); - elseif ismember (class (A), widenableToDoubleIntTypes) + elseif (ismember (class (A), widenableToDoubleIntTypes)) pkA = double (A); pkB = double (B); else @@ -131,12 +131,12 @@ outA = A; outB = B; widenableToDoubleIntTypes = {'uint8' 'int8' 'uint16' 'int16' 'uint32' 'int32'}; - if isa (A, 'double') && isa (B, 'single') + if (isa (A, 'double') && isa (B, 'single')) outB = double (B); - elseif isa (A, 'single') && isa (B, 'double') + elseif (isa (A, 'single') && isa (B, 'double')) outA = double (A); - elseif ismember (class (A), widenableToDoubleIntTypes) ... - && ismember (class (B), widenableToDoubleIntTypes) + elseif (ismember (class (A), widenableToDoubleIntTypes) ... + && ismember (class (B), widenableToDoubleIntTypes)) outA = double(A); outB = double(B); endif @@ -144,19 +144,19 @@ function pk = proxykeysForOneMatrix (A) # Special-case optimizations - if isa (A, 'double') + if (isa (A, 'double')) pk = A; - return; - elseif isa (A, 'single') + return + elseif (isa (A, 'single')) pk = double (A); - return; - elseif ismember (class (A), {'uint8' 'int8' 'uint16' 'int16' 'uint32' 'int32'}) + return + elseif (ismember (class (A), {'uint8' 'int8' 'uint16' 'int16' 'uint32' 'int32'})) # Note that (u)int64 is not included here; it cannot be losslessly widened to double pk = double (A); - return; - elseif isa (A, 'datetime') + return + elseif (isa (A, 'datetime')) pk = datenum (A); - return; + return endif # General case: use the "unique() trick" diff --git a/inst/scalarexpand.m b/inst/scalarexpand.m index 49062738..cf988896 100644 --- a/inst/scalarexpand.m +++ b/inst/scalarexpand.m @@ -49,12 +49,12 @@ sz = []; for i = 1:nargin - if !isscalar (varargin{i}) + if (! isscalar (varargin{i})) sz_i = size (varargin{i}); - if isempty (sz) + if (isempty (sz)) sz = sz_i; else - if !isequal (sz, sz_i) + if (! isequal (sz, sz_i)) error ('Matrix dimensions must agree (%s vs %s)',... tblish.internal.chrono.size2str (sz), tblish.internal.chrono.size2str (sz_i)) endif @@ -64,12 +64,12 @@ varargout = varargin; - if isempty (sz) + if (isempty (sz)) return endif for i = 1:nargin - if isscalar (varargin{i}) + if (isscalar (varargin{i})) varargout{i} = repmat (varargin{i}, sz); endif endfor diff --git a/inst/seconds.m b/inst/seconds.m index 6d0e141a..6e082270 100644 --- a/inst/seconds.m +++ b/inst/seconds.m @@ -35,7 +35,7 @@ # If input is numeric, returns a @duration array that is that many seconds long. # # If input is a duration, converts the duration to a number of seconds. - if isnumeric (x) + if (isnumeric (x)) out = duration.ofDays (double (x) / (24 * 60 * 60)); else error ('Invalid input: expected numeric or duration; got %s', class (x)); diff --git a/inst/shims/compat/all/isstring.m b/inst/shims/compat/all/isstring.m index da51522e..7252ceb5 100644 --- a/inst/shims/compat/all/isstring.m +++ b/inst/shims/compat/all/isstring.m @@ -26,5 +26,5 @@ ## @end deftypefn function out = isstring (x) - out = isa (x, 'string'); + out = isa (x, "string"); endfunction diff --git a/inst/shims/compat/pre-5.0.0/isfile.m b/inst/shims/compat/pre-5.0.0/isfile.m index a0630da8..08fce235 100644 --- a/inst/shims/compat/pre-5.0.0/isfile.m +++ b/inst/shims/compat/pre-5.0.0/isfile.m @@ -41,9 +41,9 @@ function out = isfile (file) st = stat (file); - if isempty (st) + if (isempty (st)) out = false; return endif - out = st.modestr(1) != 'd'; + out = st.modestr(1) != "d"; endfunction diff --git a/inst/shims/compat/pre-5.0.0/isfolder.m b/inst/shims/compat/pre-5.0.0/isfolder.m index f4aa8af4..81333fe8 100644 --- a/inst/shims/compat/pre-5.0.0/isfolder.m +++ b/inst/shims/compat/pre-5.0.0/isfolder.m @@ -38,9 +38,9 @@ function out = isfolder (file) st = stat (file); - if isempty (st) + if (isempty (st)) out = false; return endif - out = st.modestr(1) == 'd'; + out = st.modestr(1) == "d"; endfunction diff --git a/inst/shims/compat/pre-6.0.0/mustBeFinite.m b/inst/shims/compat/pre-6.0.0/mustBeFinite.m index 2b13d39f..fb1e821e 100644 --- a/inst/shims/compat/pre-6.0.0/mustBeFinite.m +++ b/inst/shims/compat/pre-6.0.0/mustBeFinite.m @@ -28,13 +28,13 @@ ## @end deftypefn function x = mustBeFinite (x, label) - if nargin < 2; label = []; endif + if (nargin < 2); label = []; endif tf = isfinite (x); - if ! all (tf) - if isempty (label) + if (! all (tf)) + if (isempty (label)) label = inputname (1); endif - if isempty (label) + if (isempty (label)) label = "input"; endif ix_bad = find (!tf); diff --git a/inst/shims/compat/pre-6.0.0/mustBeInteger.m b/inst/shims/compat/pre-6.0.0/mustBeInteger.m index 7d71daae..ec4af4c0 100644 --- a/inst/shims/compat/pre-6.0.0/mustBeInteger.m +++ b/inst/shims/compat/pre-6.0.0/mustBeInteger.m @@ -28,25 +28,25 @@ ## @end deftypefn function x = mustBeInteger (x, label) - if nargin < 2; label = []; endif + if (nargin < 2); label = []; endif if isinteger (x) || islogical (x) return endif but = []; - if ! isnumeric (x) + if (! isnumeric (x)) but = sprintf ("it was non-numeric (got a %s)", class (x)); - elseif any (! isfinite (x)) + elseif (any (! isfinite (x))) but = "there were Inf values"; - elseif ! isreal (x) + elseif (! isreal (x)) but = "it was complex"; - elseif ! all (floor (x) == x) + elseif (! all (floor (x) == x)) but = "it had fractional values in some elements"; endif - if ! isempty (but) - if isempty (label) + if (! isempty (but)) + if (isempty (label)) label = inputname (1); endif - if isempty (label) + if (isempty (label)) label = "input"; endif error ("%s must be integer-valued; but %s", ... diff --git a/inst/shims/compat/pre-6.0.0/mustBeMember.m b/inst/shims/compat/pre-6.0.0/mustBeMember.m index 3ee18822..9e6db062 100644 --- a/inst/shims/compat/pre-6.0.0/mustBeMember.m +++ b/inst/shims/compat/pre-6.0.0/mustBeMember.m @@ -32,13 +32,13 @@ ## @end deftypefn function x = mustBeMember (x, valid, label) - if nargin < 2; label = []; endif + if (nargin < 2); label = []; endif tf = ismember (x, valid); - if ! all (tf) - if isempty (label) + if (! all (tf)) + if (isempty (label)) label = inputname (1); endif - if isempty (label) + if (isempty (label)) label = "input"; endif n_bad = numel (find (! tf)); diff --git a/inst/shims/compat/pre-6.0.0/mustBeNonempty.m b/inst/shims/compat/pre-6.0.0/mustBeNonempty.m index e612cdfc..4d87d0e7 100644 --- a/inst/shims/compat/pre-6.0.0/mustBeNonempty.m +++ b/inst/shims/compat/pre-6.0.0/mustBeNonempty.m @@ -28,12 +28,12 @@ ## @end deftypefn function x = mustBeNonempty (x, label) - if nargin < 2; label = []; endif - if isempty (x) - if isempty (label) + if (nargin < 2); label = []; endif + if (isempty (x)) + if (isempty (label)) label = inputname (1); endif - if isempty (label) + if (isempty (label)) label = "input"; endif error ("%s must be nonempty; got a %s empty", ... diff --git a/inst/shims/compat/pre-6.0.0/mustBeNumeric.m b/inst/shims/compat/pre-6.0.0/mustBeNumeric.m index be3a92a1..835e9ad9 100644 --- a/inst/shims/compat/pre-6.0.0/mustBeNumeric.m +++ b/inst/shims/compat/pre-6.0.0/mustBeNumeric.m @@ -28,9 +28,9 @@ ## @end deftypefn function mustBeNumeric (x) - if !isnumeric (x) + if (! isnumeric (x)) name = inputname (1); - if isempty (name) + if (isempty (name)) name = 'Input'; endif error ('mustBeNumeric: %s must be numeric; got a %s', name, class (x)); diff --git a/inst/shims/compat/pre-6.0.0/mustBeReal.m b/inst/shims/compat/pre-6.0.0/mustBeReal.m index 8226a067..439a0176 100644 --- a/inst/shims/compat/pre-6.0.0/mustBeReal.m +++ b/inst/shims/compat/pre-6.0.0/mustBeReal.m @@ -28,12 +28,12 @@ ## @end deftypefn function x = mustBeReal (x, label) - if nargin < 2; label = []; endif - if ! isreal (x) - if isempty (label) + if (nargin < 2); label = []; endif + if (! isreal (x)) + if (isempty (label)) label = inputname (1); endif - if isempty (label) + if (isempty (label)) label = "input"; endif error ("%s must be real; got a complex value", ... diff --git a/inst/shims/compat/pre-7.0.0/endsWith.m b/inst/shims/compat/pre-7.0.0/endsWith.m index 2967284a..7df29026 100644 --- a/inst/shims/compat/pre-7.0.0/endsWith.m +++ b/inst/shims/compat/pre-7.0.0/endsWith.m @@ -35,7 +35,7 @@ function out = endsWith (str, pattern, varargin) [opts, args] = peelOffNameValueOptions (varargin, {'IgnoreCase'}); ignore_case = false; - if isfield (opts, 'IgnoreCase') + if (isfield (opts, 'IgnoreCase')) mustBeScalarLogical (opts.IgnoreCase, 'IgnoreCase option'); ignore_case = opts.IgnoreCase; endif @@ -43,12 +43,12 @@ str = cellstr (str); pattern = cellstr (pattern); - if any (cellfun ('isempty', pattern(:))) + if (any (cellfun ('isempty', pattern(:)))) out = true (size (str)); return; endif - if ignore_case + if (ignore_case) str = lower (str); pattern = lower (pattern); endif @@ -58,11 +58,11 @@ for i_pattern = 1:numel (pattern) pat = pattern{i_pattern}; n = numel(pat); - if n > numel (s) + if (n > numel (s)) continue endif tf = isequal (s(end-n+1:end), pat); - if tf + if (tf) out(i_str) = true; break endif diff --git a/inst/shims/compat/pre-7.0.0/startsWith.m b/inst/shims/compat/pre-7.0.0/startsWith.m index cf50c354..f91f8c9e 100644 --- a/inst/shims/compat/pre-7.0.0/startsWith.m +++ b/inst/shims/compat/pre-7.0.0/startsWith.m @@ -35,7 +35,7 @@ function out = startsWith (str, pattern, varargin) [opts, args] = peelOffNameValueOptions (varargin, {'IgnoreCase'}); ignore_case = false; - if isfield (opts, 'IgnoreCase') + if (isfield (opts, 'IgnoreCase')) mustBeScalarLogical (opts.IgnoreCase, 'IgnoreCase option'); ignore_case = opts.IgnoreCase; endif @@ -43,7 +43,7 @@ str = cellstr (str); pattern = cellstr (pattern); - if any (cellfun ('isempty', pattern(:))) + if (any (cellfun ('isempty', pattern(:)))) out = true (size (str)); return; endif @@ -52,12 +52,12 @@ for i_str = 1:numel (str) for i_pattern = 1:numel (pattern) pat = pattern{i_pattern}; - if ignore_case + if (ignore_case) tf = strncmpi (str{i_str}, pat, numel (pat)); else tf = strncmp (str{i_str}, pat, numel (pat)); endif - if tf + if (tf) out(i_str) = true; break endif diff --git a/inst/string.m b/inst/string.m index 762412f3..de387751 100644 --- a/inst/string.m +++ b/inst/string.m @@ -112,11 +112,11 @@ ## ## @end deftypefn function out = empty (varargin) - if nargin == 0 + if (nargin == 0) out = string ([]); - elseif nargin == 1 + elseif (nargin == 1) sz = varargin{1}; - if isscalar (sz) + if (isscalar (sz)) sz(2) = 0; endif out = reshape (string ([]), sz); @@ -141,7 +141,7 @@ ## ## @end deftypefn function out = missing (sz) - if nargin < 2 + if (nargin < 2) out = string (missing); else out = repmat (string (missing), sz); @@ -179,10 +179,10 @@ # (empty strings, NaN, NaT) to string missings. # # TODO: Maybe fall back to calling cellstr() on arbitrary input objects. - if nargin == 0 - return; + if (nargin == 0) + return endif - if isa(in, "string") + if (isa (in, "string")) # Copy properties, because I don't know if a full-array pass-through # works in Octave. -apj # this = in; % That is, don't do this. @@ -190,51 +190,51 @@ this.tfMissing = in.tfMissing; return endif - if ischar (in) + if (ischar (in)) this.strs = cellstr (in); this.tfMissing = false (size (this.strs)); - elseif iscell (in) - if ! iscellstr (in) + elseif (iscell (in)) + if (! iscellstr (in)) error ('string: cell inputs must be cellstr'); endif this.strs = in; this.tfMissing = false (size (this.strs)); - elseif isnumeric (in) + elseif (isnumeric (in)) tfNan = isnan (in); this.tfMissing = tfNan; - if any(tfNan(:)) + if (any (tfNan(:))) strs = repmat ({''}, size (in)); strs(!tfNan) = arrayfun (@(x) {num2str(x)}, in(!tfNan)); this.strs = strs; else this.strs = arrayfun (@(x) {num2str(x)}, in); endif - elseif islogical (in) + elseif (islogical (in)) strs = repmat ({'false'}, size (in)); strs(in) = {'true'}; this.strs = strs; this.tfMissing = false (size (in)); - elseif isa (in, 'datetime') + elseif (isa (in, 'datetime')) tfNat = isnat (in); this.tfMissing = tfNat; - if any(tfNat(:)) + if (any (tfNat(:))) strs = repmat ({''}, size (in)); strs(!tfNat) = arrayfun (@(x) {datestr(x)}, in(!tfNat)); this.strs = strs; else this.strs = arrayfun (@(x) {datestr(x)}, in); endif - elseif isa (in, 'duration') || isa (in, 'calendarDuration') + elseif (isa (in, 'duration') || isa (in, 'calendarDuration')) tfNat = isnat (in); this.tfMissing = tfNat; - if any(tfNat(:)) + if (any (tfNat(:))) strs = repmat ({''}, size (in)); strs(!tfNat) = dispstrs (in(!tfNat)); this.strs = strs; else this.strs = dispstrs (in); endif - elseif isa (in, 'missing') + elseif (isa (in, 'missing')) this.strs = repmat ({''}, size (in)); this.tfMissing = true (size (in)); else @@ -260,21 +260,21 @@ function display (this) #DISPLAY Custom display in_name = inputname(1); - if !isempty(in_name) - fprintf('%s =\n', in_name); + if (! isempty(in_name)) + fprintf ('%s =\n', in_name); endif - disp(this); + disp (this); endfunction function disp (this) #DISP Custom display - if isempty (this) + if (isempty (this)) fprintf ('Empty %s string\n', size2str (size (this))); return endif my_dispstrs = this.dispstrs; out = format_dispstr_array (my_dispstrs); - fprintf("%s", out); + fprintf ("%s", out); endfunction ## -*- texinfo -*- @@ -419,8 +419,8 @@ function disp (this) args = varargin; out = args; for i = 1:numel(args) - if isa (args{i}, 'string') - if isscalar (args{i}) + if (isa (args{i}, 'string')) + if (isscalar (args{i})) out{i} = char (args{i}); else out{i} = cellstr (args{i}); @@ -514,7 +514,7 @@ function disp (this) function out = strlength(this) out = NaN (size(this)); for i = 1:numel (out) - if this.tfMissing(i) + if (this.tfMissing(i)) continue endif utf16 = unicode2native (this.strs{i}, 'UTF-16LE'); @@ -567,7 +567,7 @@ function disp (this) points = codepoints (this); rev_points = points; for i = 1:numel (this) - if this.tfMissing(i) + if (this.tfMissing(i)) continue endif rev_points{i} = points{i}(end:-1:1); @@ -797,14 +797,14 @@ function disp (this) for i = 1:numel (A) a = A.strs{i}; b = B.strs{i}; - if isequal (a, b) + if (isequal (a, b)) out(i) = 0; else # This implementation is gross, but it's the best I can do with what # the base language provides. - apj tmp = [a b]; [tmp2, ix] = sort (tmp); - if ix(1) == 1 + if (ix(1) == 1) out(i) = -1; else out(i) = 1; @@ -907,7 +907,7 @@ function disp (this) # TODO: Handle missings. args = demote_strings (varargin); out = fprintf (args{:}); - if nargout == 0 + if (nargout == 0) clear out endif endfunction @@ -916,9 +916,9 @@ function disp (this) #PRINTF Formatted output # # TODO: Handle missings. - args = demote_strings( varargin); + args = demote_strings (varargin); printf (args{:}); - if nargout == 0 + if (nargout == 0) clear out endif endfunction @@ -1014,7 +1014,7 @@ function disp (this) function out = size (this, dim) #SIZE Size of array. - if nargin == 1 + if (nargin == 1) out = size (this.strs); else out = size (this.strs, dim); @@ -1111,7 +1111,7 @@ function disp (this) function [this, nshifts] = shiftdim( this, n) #SHIFTDIM Shift dimensions. - if nargin > 1 + if (nargin > 1) this.strs = shiftdim (this.strs, n); this.tfMissing = shiftdim (this.strs, n); else @@ -1123,16 +1123,16 @@ function disp (this) function out = cat (dim, varargin) #CAT Concatenate arrays. args = varargin; - for i = 1:numel(args) - if !isa(args{i}, 'string') - args{i} = string(args{i}); + for i = 1:numel (args) + if (! isa (args{i}, 'string')) + args{i} = string (args{i}); endif endfor out = args{1}; - fieldArgs1 = cellfun(@(obj) {obj.strs}, args); - out.strs = cat(dim, fieldArgs1{:}); - fieldArgs2 = cellfun(@(obj) {obj.tfMissing}, args); - out.tfMissing = cat(dim, fieldArgs2{:}); + fieldArgs1 = cellfun (@(obj) {obj.strs}, args); + out.strs = cat (dim, fieldArgs1{:}); + fieldArgs2 = cellfun (@(obj) {obj.tfMissing}, args); + out.tfMissing = cat (dim, fieldArgs2{:}); endfunction function out = horzcat (varargin) @@ -1149,7 +1149,7 @@ function disp (this) #SUBSASGN Subscripted assignment. # Chained subscripts - if numel(s) > 1 + if (numel (s) > 1) rhs_in = subsref(this, s(1)); rhs = subsasgn(rhs_in, s(2:end), b); else @@ -1157,7 +1157,7 @@ function disp (this) endif # Base case - switch s(1).type + switch (s(1).type) case '()' this = subsasgnParensPlanar(this, s(1), rhs); case '{}' @@ -1173,7 +1173,7 @@ function disp (this) #SUBSREF Subscripted reference. # Base case - switch s(1).type + switch (s(1).type) case '()' varargout = { subsrefParensPlanar(this, s(1)) }; case '{}' @@ -1185,7 +1185,7 @@ function disp (this) endswitch # Chained reference - if numel (s) > 1 + if (numel (s) > 1) out = subsref (out, s(2:end)); endif endfunction @@ -1196,7 +1196,7 @@ function disp (this) function this = subsasgnParensPlanar (this, s, rhs) #SUBSASGNPARENSPLANAR ()-assignment for planar object - if !isa (rhs, 'string') + if (! isa (rhs, 'string')) rhs = string (rhs); endif this.strs(s.subs{:}) = rhs.strs; @@ -1228,12 +1228,12 @@ function disp (this) # This is what you call internally inside the class instead of doing # ()-indexing references on the LHS, which don't work properly inside # the class because they don't respect the subsasgn() override. - if !iscell(ix) + if (! iscell (ix)) ix = { ix }; endif s.type = '()'; s.subs = ix; - out = subsasgnParensPlanar(this, s, value); + out = subsasgnParensPlanar (this, s, value); endfunction endmethods @@ -1266,7 +1266,7 @@ function disp (this) # # This is the inverse of codepoints(). persistent native_utf32_encoding - if isempty (native_utf32_encoding) + if (isempty (native_utf32_encoding)) [~,~,endian] = computer (); native_utf32_encoding = sprintf ('UTF-32%cE', endian); endif @@ -1317,7 +1317,7 @@ function disp (this) #PROMOTEC Promote arguments to strings varargout = varargin; for i = 1:numel (varargin) - if !isa (varargin{i}, 'string') + if (! isa (varargin{i}, 'string')) varargout{i} = string (varargin{i}); endif endfor @@ -1328,7 +1328,7 @@ function disp (this) #PROMOTEC Promote arguments to strings, cell-wise out = args; for i = 1:numel (args) - if !isa (args{i}, 'string') + if (! isa (args{i}, 'string')) out{i} = string (args{i}); endif endfor diff --git a/inst/struct2table.m b/inst/struct2table.m index 94fbed98..7b1f90d4 100644 --- a/inst/struct2table.m +++ b/inst/struct2table.m @@ -32,16 +32,16 @@ # Peel off trailing options [opts, args] = peelOffNameValueOptions (varargin, {'AsArray'}); - if isfield (opts, 'AsArray') && opts.AsArray + if (isfield (opts, 'AsArray') && opts.AsArray) error ('struct2table: AsArray option is currently unimplemented'); endif - if !isempty (args) + if (! isempty (args)) error ('struct2table: Unrecognized options'); endif # Conversion logic varNames = fieldnames (s); - if isscalar (s) + if (isscalar (s)) varValues = struct2cell (s); out = table (varValues{:}, 'VariableNames', varNames); else diff --git a/inst/table.m b/inst/table.m index 22486bf3..a10296e3 100644 --- a/inst/table.m +++ b/inst/table.m @@ -74,7 +74,7 @@ # Optional row names, as cellstr RowNames = [] # Dimension names - DimensionNames = { "Row" "Variables" } + DimensionNames = {"Row", "Variables"} endproperties methods @@ -120,7 +120,7 @@ # Special internal-use calling forms # Handle these first to avoid getting mixed up with general arg-parsing code - if nargin == 3 && isequal (varargin{1}, '__tblish_backdoor__') + if (nargin == 3 && isequal (varargin{1}, '__tblish_backdoor__')) # Undocumented form for internal use; not part of table's public interface. # # This backdoor form provides a uniform interface for constructing tables with @@ -141,7 +141,7 @@ [opts, args] = peelOffNameValueOptions (varargin, optNames); optsPresent = fieldnames (opts); tfUnsupp = ismember (optsPresent, unsupportedOptions); - if any (tfUnsupp) + if (any (tfUnsupp)) error ('table: unsupported constructor options: %s', ... strjoin (optsPresent(tfUnsupp), ', ')) endif @@ -150,15 +150,15 @@ # Special case for "preallocation constructor" form preallocOptions = {'Size', 'VariableTypes'}; tfPrealloc = ismember (preallocOptions, fieldnames (opts)); - if any (tfPrealloc) - if ~all (tfPrealloc) + if (any (tfPrealloc)) + if (! all (tfPrealloc)) error (['table: invalid constructor call: if any of the options (%s) are ' ... 'given, they all must be. Missing: %s'], ... strjoin (preallocOptions, ', '), strjoin (preallocOptions(!tfPrealloc), ', ')) endif # Copy fields from a new object bc I don't know if Octave supports 'this' # replacement in constructors. - if isfield (opts, 'VariableNames') + if (isfield (opts, 'VariableNames')) varNames = opts.VariableNames; else varNames = []; @@ -175,7 +175,7 @@ nVars = numel (args); varVals = args; - if isfield (opts, 'VariableNames') + if (isfield (opts, 'VariableNames')) varNames = opts.VariableNames; else # Infer variable names from argin names @@ -183,44 +183,44 @@ defaultVarNames = tblish.internal.table.defaultVarNames (nVars); for i = 1:numel (args) varNames{i} = inputname (i); - if isempty (varNames{i}) + if (isempty (varNames{i})) varNames{i} = defaultVarNames{i}; endif endfor endif # Input validation - if !iscell (varVals) || (!isvector (varVals) && !isempty (varVals)) - error('table: VariableValues must be a cell vector'); + if (! iscell (varVals) || (! isvector (varVals) && ! isempty (varVals))) + error ('table: VariableValues must be a cell vector'); endif - if isstring (varNames) + if (isstring (varNames)) varNames = cellstr (varNames); endif - if !iscellstr (varNames) || (!isvector (varNames) && !isempty (varNames)) - error('table: VariableNames must be a cellstr vector'); + if (! iscellstr (varNames) || (! isvector (varNames) && ! isempty (varNames))) + error ('table: VariableNames must be a cellstr vector'); endif varNames = varNames(:)'; varVals = varVals(:)'; - if numel (varNames) ~= numel (varVals) + if (numel (varNames) != numel (varVals)) error ('table: Inconsistent number of VariableNames (%d) and VariableValues (%d)', ... numel (varNames), numel (varVals)); endif - if !isempty (varVals) + if (! isempty (varVals)) nRows = size (varVals{1}, 1); for i = 2:numel (varVals) - if ndims (varVals{i}) > 2 + if (ndims (varVals{i}) > 2) error (['table: Variable values may not have > 2 dimensions; ' ... 'input %d (%s) has %d'], i, varNames{i}, ndims (varVals{i})); endif nRows2 = size (varVals{i}, 1); - if nRows ~= nRows2 + if (nRows != nRows2) error ('table: Inconsistent sizes: var 1 (%s) is %d rows; var %d (%s) is %d rows', ... varNames{1}, nRows, i, varNames{i}, nRows2); endif endfor endif [uqNames, ix] = unique (varNames); - if numel (uqNames) < numel (varNames) + if (numel (uqNames) < numel (varNames)) ixBad = 1:numel (varNames); ixBad(ix) = []; error ('table: Duplicate VariableNames: %s', strjoin (varNames(ixBad), ', ')); @@ -229,10 +229,10 @@ # Construction this.VariableNames = varNames; this.VariableValues = varVals; - if isfield (opts, 'RowNames') + if (isfield (opts, 'RowNames')) this.RowNames = opts.RowNames; endif - if isfield (opts, 'DimensionNames') + if (isfield (opts, 'DimensionNames')) this.DimensionNames = opts.DimensionNames; endif endfunction @@ -242,7 +242,7 @@ function display (this) #DISPLAY Custom display. in_name = inputname (1); - if !isempty (in_name) + if (! isempty (in_name)) fprintf ('%s =\n', in_name); endif disp (this); @@ -250,12 +250,12 @@ function display (this) function disp (this) #DISP Custom display. - if isempty (this) + if (isempty (this)) fprintf ('Empty %s %s\n', size2str (size (this)), class (this)); else fprintf ('table: %d rows x %d variables\n', height (this), width (this)); fprintf (' VariableNames: %s\n', strjoin (this.VariableNames, ', ')); - if hasrownames (this) + if (hasrownames (this)) fprintf (' Has RowNames\n'); endif endif @@ -288,7 +288,7 @@ function disp (this) ## @end deftypefn function prettyprint (this) #PRETTYPRINT Display table values, formatted as a table - if isempty (this) + if (isempty (this)) fprintf ('Empty %s %s\n', size2str (size (this)), class (this)); return endif @@ -311,7 +311,7 @@ function prettyprint (this) endfor colStrs{iVar} = lines; endfor - if hasrownames (this) + if (hasrownames (this)) colStrs = [{this.RowNames(:)} colStrs]; colNames = [{'RowName'} colNames]; nCols++; @@ -358,8 +358,8 @@ function prettyprint (this) out = cell (size (this)); for i = 1:width (this) varVal = this.VariableValues{i}; - if iscell (varVal) - if size (varVal, 2) == 1 + if (iscell (varVal)) + if (size (varVal, 2) == 1) out(:,i) = varVal; else out(:,i) = mat2cell (varVal, ones (1, size (varVal, 2))); @@ -389,13 +389,13 @@ function prettyprint (this) function out = table2struct (this, varargin) [opts, args] = peelOffNameValueOptions (varargin, {'ToScalar'}); toScalar = false; - if isfield (opts, 'ToScalar') + if (isfield (opts, 'ToScalar')) mustBeA (opts.ToScalar, 'logical'); mustBeScalar (opts.ToScalar); toScalar = opts.ToScalar; endif - if toScalar + if (toScalar) out = struct; for i = 1:width (this) out.(this.VariableNames{i}) = this.VariableValues{i}; @@ -410,7 +410,7 @@ function prettyprint (this) for iVar = 1:width (this) varVal = this.VariableValues{iVar}; for iRow = 1:height (this) - if iscell (varVal) && size (varVal, 2) == 1 + if (iscell (varVal) && size (varVal, 2) == 1) elVal = varVal{iRow}; else elVal = varVal(iRow,:); @@ -430,7 +430,7 @@ function prettyprint (this) ## @end deftypefn function out = table2array (this) #TABLE2ARRAY Convert table to homogeneous array - if isempty (this) + if (isempty (this)) out = []; return endif @@ -455,7 +455,7 @@ function prettyprint (this) ## ## @end deftypefn function out = varnames (this, newVarNames) - if nargin == 1 + if (nargin == 1) out = this.VariableNames; else out = this; @@ -489,15 +489,15 @@ function prettyprint (this) ## @end deftypefn function varargout = size (this, dim) varargout = cell(1, nargout); - if nargin == 2 - if dim == 1 + if (nargin == 2) + if (dim == 1) varargout{1} = height(this); - elseif dim == 2 + elseif (dim == 2) varargout{1} = width(this); else varargout{1} = 1; endif - elseif nargout == 0 || nargout == 1 + elseif (nargout == 0 || nargout == 1) varargout{1} = [height(this), width(this)]; else varargout{1} = height(this); @@ -578,9 +578,9 @@ function prettyprint (this) out = true; for i = 2:numel (varargin) [nrowsi, nvarsi] = size (varargin{i}); - if nrowsi ~= nrows || nvarsi ~= nvars; + if (nrowsi != nrows || nvarsi != nvars) out = false; - return; + return endif endfor endfunction @@ -615,7 +615,7 @@ function prettyprint (this) ## @end deftypefn function out = height (this) #HEIGHT Number of rows in table - if isempty (this.VariableValues) + if (isempty (this.VariableValues)) out = 0; else out = size (this.VariableValues{1}, 1); @@ -777,7 +777,7 @@ function prettyprint (this) ## @end deftypefn function out = hasrownames (this) #HASROWNAMES True if this table has row names defined - out = !isempty (this.RowNames); + out = ! isempty (this.RowNames); endfunction ## -*- texinfo -*- @@ -798,15 +798,15 @@ function prettyprint (this) function out = vertcat (varargin) args = varargin; for i = 1:numel (args) - if !istable (args{i}) + if (! istable (args{i})) args{i} = table (args{i}); endif endfor mustBeAllSameVars (args{:}); out = args{1}; for i = 2:numel (args) - if isempty (out.RowNames) - if !isempty (args{i}.RowNames) + if (isempty (out.RowNames)) + if (! isempty (args{i}.RowNames)) error ('table.vertcat: Cannot cat tables with mixed empty and non-empty RowNames'); endif else @@ -839,7 +839,7 @@ function prettyprint (this) seen_names = args{1}.VariableNames; for i = 2:numel (args) dup_names = intersect (seen_names, args{i}.VariableNames); - if !isempty (dup_names) + if (! isempty (dup_names)) error ('table.horzcat: Inputs have duplicate VariableNames: %s', strjoin (dup_names, ', ')); endif seen_names = [seen_names args{i}.VariableNames]; @@ -874,14 +874,14 @@ function prettyprint (this) function out = repmat (this, sz) mustBeA (this, 'table'); mustBeNumeric (sz); - if any (sz(2:end) != 1) + if (any (sz(2:end) != 1)) error ('table.repmat: all size elements for dim 2 and higher must be 1'); endif out = this; for i = 1:numel (this.VariableValues) out.VariableValues{i} = repmat (this.VariableValues{i}, sz); endfor - if ! isempty (this.RowNames) + if (! isempty (this.RowNames)) out.RowNames = repmat (this.RowNames, sz); endif endfunction @@ -901,7 +901,7 @@ function prettyprint (this) ## @end deftypefn function out = repelem(this, varargin); args = varargin; - if numel (args) > 2 + if (numel (args) > 2) error ("table.repelem: Only 2 dimensions are supported for repelem on tables"); endif out = this; @@ -924,9 +924,9 @@ function prettyprint (this) # table or get at the variable values within the table. chain_s = s(2:end); s = s(1); - switch s(1).type + switch (s(1).type) case '()' - if numel (s.subs) ~= 2 + if (numel (s.subs) != 2) error ('table.subsref: ()-indexing of table requires exactly two arguments'); endif [ixRow, ixVar] = resolveRowVarRefs (this, s.subs{1}, s.subs{2}); @@ -934,41 +934,41 @@ function prettyprint (this) out = subsetrows (out, ixRow); out = subsetvars (out, ixVar); case '{}' - if numel (s.subs) ~= 2 + if (numel (s.subs) != 2) error ('table.subsref: {}-indexing of table requires exactly two arguments'); endif [ixRow, ixVar] = resolveRowVarRefs (this, s.subs{1}, s.subs{2}); - if numel (ixRow) ~= 1 && numel (ixVar) ~= 1 + if (numel (ixRow) != 1 && numel (ixVar) != 1) error('table.subsref: {}-indexing of table requires one of the inputs to be scalar'); endif #FIXME: I'm not sure how to handle the signature here yet - if numel (ixVar) > 1 + if (numel (ixVar) > 1) error ('table.subsref: {}-indexing across multiple variables is currently unimplemented'); endif - if numel (ixRow) > 1 + if (numel (ixRow) > 1) error ('table.subsref: {}-indexing across multiple rows is currently unimplemented'); endif varData = this.VariableValues{ixVar}; out = varData(ixRow); case '.' name = s.subs; - if !ischar (name) + if (! ischar (name)) error ('table.subsref: .-reference arguments must be char'); endif # Special cases for special properties and other attribute access # TODO: should variable names or dimension names take precedence? - if isequal (name, 'Properties') + if (isequal (name, 'Properties')) out = getProperties (this); - elseif isequal (name, this.DimensionNames{1}) + elseif (isequal (name, this.DimensionNames{1})) out = this.RowNames; - elseif isequal (name, this.DimensionNames{2}) + elseif (isequal (name, this.DimensionNames{2})) out = this.VariableNames; else out = getvar (this, name); endif endswitch # Chained references - if !isempty (chain_s) + if (! isempty (chain_s)) out = subsref (out, chain_s); endif endfunction @@ -979,7 +979,7 @@ function prettyprint (this) # Chained subscripts chain_s = s(2:end); s = s(1); - if !isempty (chain_s) + if (! isempty (chain_s)) rhs_in = subsref (this, s); rhs = subsasgn (rhs_in, chain_s, val); else @@ -987,15 +987,15 @@ function prettyprint (this) endif out = this; - switch s(1).type + switch (s(1).type) case '()' error ('table.subsasgn: Assignment using ()-indexing is not supported for table'); case '{}' - if numel (s.subs) ~= 2 + if (numel (s.subs) != 2) error ('table.subsasgn: {}-indexing of table requires exactly two arguments'); endif [ixRow, ixVar] = resolveRowVarRefs (this, s.subs{1}, s.subs{2}); - if !isscalar (ixVar) + if(! isscalar (ixVar)) error ('table.subsasgn: {}-indexing must reference a single variable; got %d', ... numel (ixVar)); endif @@ -1003,11 +1003,11 @@ function prettyprint (this) varData(ixRow) = rhs; out.VariableValues{ixVar} = varData; case '.' - if !ischar (s.subs) + if (! ischar (s.subs)) error ('table.subsasgn: .-index argument must be char; got a %s', ... class (s.subs)); endif - if isequal (s.subs, 'Properties') + if (isequal (s.subs, 'Properties')) # Special case for this.Properties access error ('table.subsasgn: .Properties access is not implemented yet'); else @@ -1038,29 +1038,29 @@ function prettyprint (this) function this = setVariableNames (this, varargin) #SETVARIABLENAMES Set VariableNames narginchk (2, 3); - if nargin == 2 + if (nargin == 2) ix = []; names = varargin{1}; else [ix, names] = varargin{:}; endif - if ischar (names) + if (ischar (names)) names = cellstr (names); endif mustBeCellstr (names); - if isempty (ix) + if (isempty (ix)) n_assigned = width (this); else n_assigned = numel (ix); endif - if numel (names) != n_assigned + if (numel (names) != n_assigned) error ('table: Dimension mismatch: assigning to %d variable names but new VariableNames is %d-long', ... n_assigned, numel (names)); endif - if isempty (ix) + if (isempty (ix)) this.VariableNames = names; else - if any (ix > width (this)) + if (any (ix > width (this))) error ('table: index out of range during variable name assignment: %d (vs. %d variables in this)', ... max (ix), width (this)); endif @@ -1090,32 +1090,32 @@ function prettyprint (this) ## @end deftypefn function this = setDimensionNames (this, varargin) narginchk (2, 3); - if nargin == 2 + if (nargin == 2) ix = []; names = varargin{1}; else [ix, names] = varargin{:}; endif - if ischar (names) + if (ischar (names)) names = cellstr (names); endif mustBeCellstr (names); - if !all (cellfun (@isvarname, names)) + if (! all (cellfun (@isvarname, names))) error ('table.setDimensionNames: DimensionNames must be valid variable names'); endif - if isempty (ix) + if (isempty (ix)) n_assigned = 2; else n_assigned = numel (ix); endif - if numel (names) != n_assigned + if (numel (names) != n_assigned) error ('table.setDimensionNames: Dimension mismatch: assigning to %d dimension names but new DimensionNames is %d-long', ... n_assigned, numel (names)); endif - if isempty (ix) + if (isempty (ix)) this.DimensionNames = names; else - if any (ix > 2) + if (any (ix > 2)) error ('table.setDimensionNames: index out of range: %d (max is %d)', ... max (ix), 2); endif @@ -1138,14 +1138,14 @@ function prettyprint (this) ## @end deftypefn function this = setRowNames (this, names) #SETROWNAMES Set RowNames - if isempty (names) + if (isempty (names)) this.RowNames = []; return; endif - if !iscellstr (names) + if (! iscellstr (names)) error ('table: RowNames must be cellstr; got a %s', class (names)); endif - if !isequal (size (names), [height(this), 1]) + if (! isequal (size (names), [height(this), 1])) error ('table: Dimension mismatch: table has %d rows but new RowNames is %s', ... height (this), size2str (size (names))); endif @@ -1190,10 +1190,10 @@ function prettyprint (this) ## ## @end deftypefn function out = movevars (this, vars, relLocation, location) - if !ischar (relLocation) + if (! ischar (relLocation)) error ('table.movevars: relLocation must be char; got %s', class (relLocation)); endif - if !ismember (relLocation, {'Before', 'After'}) + if (! ismember (relLocation, {'Before', 'After'})) error ('table.movevars: relLocation must be ''Before'' or ''After''; got ''%s''', ... relLocation); endif @@ -1203,10 +1203,10 @@ function prettyprint (this) tmp = subsetvars (this, ixOtherVars); moved = subsetvars (this, ixVar); ixLoc = resolveVarRef (tmp, location); - if !isscalar (ixLoc) + if (! isscalar (ixLoc)) error ('table.movevars: location must specify a single existing variable'); endif - if isequal(relLocation, 'Before') + if (isequal (relLocation, 'Before')) insertionIx = ixLoc; else insertionIx = ixLoc = 1; @@ -1232,7 +1232,7 @@ function prettyprint (this) ## @end deftypefn function [out, name] = getvar (this, var_ref) [ix_var, var_names] = resolveVarRef (this, var_ref); - if ! isscalar (ix_var) + if (! isscalar (ix_var)) error ('table.getvar: getvar only accepts a single variable reference; got %d', ... numel (ix_var)); endif @@ -1282,7 +1282,7 @@ function prettyprint (this) ## @end deftypefn function out = setvar (this, varRef, value) ixVar = resolveVarRef (this, varRef, 'lenient'); - if ! isscalar (ixVar) + if (! isscalar (ixVar)) error('table.setvar: Only a single variable is allowed for varRef; got %d', ... numel (ixVar)); endif @@ -1292,19 +1292,19 @@ function prettyprint (this) n_rows = height (this); val_is_scalar = isscalar(value) || (ischar(value) && ... (size (value, 1) == 1 || isequal (size (value), [0 0]))); - if n_rows != 1 && val_is_scalar - if ischar (value) + if (n_rows != 1 && val_is_scalar) + if (ischar (value)) value = { value }; endif value = repmat (value, [n_rows 1]); endif - if size (value, 1) ~= height (this) + if (size (value, 1) != height (this)) error ('table.setvar: Inconsistent dimensions: table is height %d, input is height %d', ... height (this), size (value, 1)); endif - if ixVar == 0 + if (ixVar == 0) # Adding a variable - if ! ischar (varRef) + if (! ischar (varRef)) error (['table.setvar: When adding a variable, you must supply the ' ... 'variable name instead of an index']); endif @@ -1334,17 +1334,17 @@ function prettyprint (this) [opts, args] = peelOffNameValueOptions (varargin, ... {'Before', 'After', 'NewVariableNames'}); ix_insertion = width (this); - if isfield (opts, 'Before') + if (isfield (opts, 'Before')) ix_insertion = resolveVarRef (this, opts.Before) - 1; endif - if isfield (opts, 'After') + if (isfield (opts, 'After')) ix_insertion = resolveVarRef (this, opts.After); endif new_var_vals = args; - if isfield (opts, 'NewVariableNames') + if (isfield (opts, 'NewVariableNames')) new_var_names = opts.NewVariableNames; - if numel (new_var_names) != numel (new_var_vals) + if (numel (new_var_names) != numel (new_var_vals)) error ('table.addvars: size mismatch: got %d variables but %d names', ... numel (new_var_vals), numel (new_var_names)); endif @@ -1352,16 +1352,16 @@ function prettyprint (this) new_var_names = cell (size (args)); for i = 1:numel (new_var_vals) new_var_names{i} = inputname (i + 1); - if isempty (new_var_names{i}) + if (isempty (new_var_names{i})) error ('table.addvars: no variable name found for input %d', i + 1); endif endfor endif new_tbl = table (new_var_vals{:}, 'VariableNames', new_var_names); - if ix_insertion == width (this) + if (ix_insertion == width (this)) out = [this new_tbl]; - elseif ix_insertion == 0 + elseif (ix_insertion == 0) out = [new_tbl this]; else left = subsetvars (this, 1:ix_insertion); @@ -1392,7 +1392,7 @@ function prettyprint (this) ## ## @end deftypefn function out = convertvars (this, vars, dataType) - if !ischar (dataType) && isa (dataType, 'function_handle') + if (! ischar (dataType) && isa (dataType, 'function_handle')) error ('table.convertvars: dataType must be char or function_handle; got a %s', ... class (dataType)); endif @@ -1418,7 +1418,7 @@ function prettyprint (this) function out = mergevars (this, vars, varargin) [opts, args] = peelOffNameValueOptions (varargin, ... {'NewVariableName', 'MergeAsTable'}); - if isfield (opts, 'MergeAsTable') + if (isfield (opts, 'MergeAsTable')) merge_as_table = opts.MergeAsTable; else merge_as_table = false; @@ -1426,7 +1426,7 @@ function prettyprint (this) [ix_vars, var_names] = resolveVarRef (this, vars); [ix_vars, ix_sort] = sort(ix_vars); var_names = var_names(ix_sort); - if isfield (opts, 'NewVariableName') + if (isfield (opts, 'NewVariableName')) new_var_name = opts.NewVariableName; else new_var_name = var_names{1}; @@ -1438,7 +1438,7 @@ function prettyprint (this) merged_as_tbl = subsetvars (this, ix_vars); leftover = subsetvars (this, ix_vars_left); - if merge_as_table + if (merge_as_table) new_var_value = merged_as_tbl; else new_var_value = cat (2, merged_as_tbl.VariableValues{:}); @@ -1464,22 +1464,22 @@ function prettyprint (this) ## @end deftypefn function out = splitvars(this, varargin) [opts, args] = peelOffNameValueOptions (varargin, {'NewVariableNames'}); - if isfield (opts, 'NewVariableNames') + if (isfield (opts, 'NewVariableNames')) new_var_names = opts.NewVariableNames; else new_var_names = []; endif - if isempty(args) + if (isempty (args)) do_all_vars = true; else do_all_vars = false; vars_to_split = args{1}; endif - if do_all_vars + if (do_all_vars) vars_to_split = []; - for i=1:width (this) - if size (this.VariableValues{i}, 2) > 1 + for i = 1:width (this) + if (size (this.VariableValues{i}, 2) > 1) vars_to_split(end+1) = i; endif endfor @@ -1487,7 +1487,7 @@ function prettyprint (this) [ix_vars, old_var_names] = resolveVarRef (this, vars_to_split); [ix_vars, ix_sort] = sort (ix_vars); old_var_names = old_var_names(ix_sort); - if numel (ix_vars) > 1 && ! isempty (new_var_names) + if (numel (ix_vars) > 1 && ! isempty (new_var_names)) error ('NewVariableNames may only be specified when splitting a single variable'); endif @@ -1495,13 +1495,13 @@ function prettyprint (this) for i_var = numel(ix_vars):-1:1 ix_var = ix_vars(i_var); old_val = out.VariableValues{ix_var}; - if isa (old_val, 'table') + if (isa (old_val, 'table')) new_var_vals = old_val.VariableValues; else new_var_vals = num2cell (old_val, 1); endif - if isempty (new_var_names) - if istable (old_val) + if (isempty (new_var_names)) + if (istable (old_val)) my_new_var_names = old_val.VariableNames; else my_new_var_names = cell (size (new_var_vals)); @@ -1535,16 +1535,16 @@ function prettyprint (this) [opts, args] = peelOffNameValueOptions (varargin, ... {'NewDataVariableName', 'IndexVariableName', 'ConstantVariables'}); index_var_name = []; - if isfield (opts, 'IndexVariableName') + if (isfield (opts, 'IndexVariableName')) index_var_name = opts.IndexVariableName; endif new_data_var_name = []; - if isfield (opts, 'NewDataVariableName') + if (isfield (opts, 'NewDataVariableName')) new_data_var_name = opts.NewDataVariableName; endif [ix_vars, var_names] = resolveVarRef (this, varRef); - if isfield (opts, 'ConstantVariables') + if (isfield (opts, 'ConstantVariables')) [ix_const_vars, const_var_names] = resolveVarRef (this, opts.ConstantVariables); else ix_const_vars = setdiff (1:width (this), ix_vars); @@ -1562,10 +1562,10 @@ function prettyprint (this) stk_mat = stk_mat'; stk_var_vals = stk_mat(:); index_var_vals = repmat(ctg_run, [n_rows_orig 1]); - if isempty (new_data_var_name) + if (isempty (new_data_var_name)) new_data_var_name = strjoin(var_names, '_'); endif - if isempty (index_var_name) + if (isempty (index_var_name)) index_var_name = [new_data_var_name '_Indicator']; endif stk_tbl = table(index_var_vals, stk_var_vals, ... @@ -1589,13 +1589,13 @@ function prettyprint (this) ## ## @end deftypefn function out = head (this, k) - if nargin < 2 || isempty (k) + if (nargin < 2 || isempty (k)) k = 8; endif nRows = height (this); - if nRows < k + if (nRows < k) out = this; - return; + return endif out = subsetrows (this, 1:k); endfunction @@ -1622,13 +1622,13 @@ function prettyprint (this) # Returns the last k rows of this. K defaults to 8. # # If there are less than k rows in this, returns all rows. - if nargin < 2 || isempty (k) + if (nargin < 2 || isempty (k)) k = 8; endif nRows = height (this); - if nRows < k + if (nRows < k) out = this; - return; + return endif out = subsetrows (this, [(nRows - (k - 1)):nRows]); endfunction @@ -1658,17 +1658,17 @@ function prettyprint (this) varRef = ':'; knownOptions = {'MissingPlacement', 'ComparisonMethod'}; [opts, ~, optArgs] = peelOffNameValueOptions (args, knownOptions); - if !isempty (args) && (ischar (args{end}) || iscellstr (args{end})) ... - && all (ismember (args{end}, {'ascend','descend'})) + if (! isempty (args) && (ischar (args{end}) || iscellstr (args{end})) ... + && all (ismember (args{end}, {'ascend','descend'}))) direction = args{end}; args(end) = []; endif - if numel (args) > 1 + if (numel (args) > 1) error ('table.sortrows: Unrecognized options or arguments'); endif - if !isempty (args) + if (! isempty (args)) #FIXME: Determine how to identify the "rowDimName" argument - if ischar (args{1}) && isequal (args{1}, 'RowNames') + if (ischar (args{1}) && isequal (args{1}, 'RowNames')) doRowNames = true; else varRef = args{1}; @@ -1679,9 +1679,9 @@ function prettyprint (this) # Interpret inputs # Do sorting - if doRowNames + if (doRowNames) # Special case: sort by row names - if isempty (this.rowNames) + if (isempty (this.rowNames)) error ('table.sortrows: this table does not have row names'); endif [sortedRowNames, index] = sortrows (this.RowNames, direction, optArgs{:}); @@ -1689,15 +1689,15 @@ function prettyprint (this) else # General case ixVars = resolveVarRef (this, varRef); - if ischar (direction) + if (ischar (direction)) direction = cellstr (direction); endif - if isscalar (direction) + if (isscalar (direction)) directions = repmat (direction, size (ixVars)); else directions = direction; endif - if !isequal (size (directions), size (ixVars)) + if (! isequal (size (directions), size (ixVars))) error ('table.sortrows: inconsistent size between direction and vars specifier'); endif # Perform a radix sort on the referenced variables @@ -1711,7 +1711,7 @@ function prettyprint (this) #TODO: Add support for Octave-style negative column indexes in table.sortrows input. #TODO: Wrap this arg munging logic in a sortrows_matlabby() function #TODO: Better error message when optArgs are is present. - if isequal (directions{iVar}, 'descend') + if (isequal (directions{iVar}, 'descend')) [~, ix] = sortrows (varVal, -1 * (1:size (varVal, 2)), optArgs{:}); else [~, ix] = sortrows (varVal, optArgs{:}); @@ -1740,7 +1740,7 @@ function prettyprint (this) # # TODO: Document my signature. [sorted, ix] = sortrows (this, varargin); - if k > height (sorted) + if (k > height (sorted)) out = sorted; ia = ix; else @@ -1765,12 +1765,12 @@ function prettyprint (this) # row-wise operation is the only mode supported for unique() on tables. validFlags = {'rows', 'legacy', 'stable', 'sorted', 'first', 'last'}; redundantFlags = {'rows'}; - if !iscellstr (varargin) + if (! iscellstr (varargin)) error ('table.unique: Invalid inputs: args 2 and later must be char flags'); endif flags = varargin; invalidFlags = setdiff (varargin, validFlags); - if !isempty (invalidFlags) + if (! isempty (invalidFlags)) error ('table.unique: Invalid flags: %s', strjoin(invalidFlags, ', ')); endif tfRedundant = ismember (flags, redundantFlags); @@ -1809,33 +1809,33 @@ function prettyprint (this) opts = peelOffNameValueOptions (varargin, optNames); unimplementedOptions = optNames; for i = 1:numel (unimplementedOptions) - if isfield (opts, unimplementedOptions{i}) + if (isfield (opts, unimplementedOptions{i})) error ('table.join: Option %s is unimplemented. Sorry.', ... unimplementedOptions{i}); endif endfor - if !istable (A) + if (! istable (A)) A = table (A); endif - if !istable (B) + if (! istable (B)) B = table (B); endif # Join logic keyVarNames = intersect_stable (A.VariableNames, B.VariableNames); nonKeyVarsB = setdiff_stable (B.VariableNames, keyVarNames); - if isempty (keyVarNames) + if (isempty (keyVarNames)) error ('table.join: Cannot join: inputs have no variable names in common'); endif keysA = subsetvars (A, keyVarNames); keysB = subsetvars (B, keyVarNames); uKeysB = unique (keysB); - if height (uKeysB) < height (keysB) + if (height (uKeysB) < height (keysB)) error ('table.join: Non-unique keys in B'); endif [pkA, pkB] = proxykeysForMatrixes (keysA, keysB); [tf, ib] = ismember (pkA, pkB, 'rows'); - if !all (tf) + if (! all (tf)) error ('table.join: Some rows in A had no corresponding key values in B'); endif # TODO: Once we've applied the key restrictions, can we just call @@ -1846,11 +1846,11 @@ function prettyprint (this) C = [outA outB]; endfunction - function out = resolveJoinKeysAndVars(A, B, opts) + function out = resolveJoinKeysAndVars (A, B, opts) #RESOLVEJOINKEYSANDVARS Internal implementation method - if isfield (opts, 'Keys') - if isnumeric (opts.Keys) || islogical (opts.Keys) - if islogical (opts.Keys) + if (isfield (opts, 'Keys')) + if (isnumeric (opts.Keys) || islogical (opts.Keys)) + if (islogical (opts.Keys)) keyIxA = find (opts.Keys); keyIxB = find (opts.Keys); else @@ -1859,51 +1859,51 @@ function prettyprint (this) endif keyNamesA = A.VariableNames(keyIxA); keyNamesB = B.VariableNames(keyIxB); - elseif ischar (opts.Keys) || iscellstr (opts.Keys) + elseif (ischar (opts.Keys) || iscellstr (opts.Keys)) keyNamesA = cellstr (opts.Keys); keyNamesB = cellstr (opts.Keys); [tf, keyIxA] = ismember (keyNamesA, A.VariableNames); - if ! all (tf) + if (! all (tf)) error ('Named keys not found in table A: %s', strjoin (keyNamesA(!tf), ', ')); endif [tf, keyIxB] = ismember (keyNamesB, B.VariableNames); - if ! all (tf) + if (! all (tf)) error ('Named keys not found in table B: %s', strjoin (keyNamesB(!tf), ', ')); endif endif - elseif isfield (opts, 'LeftKeys') - if ! isfield (opts, 'RightKeys') + elseif (isfield (opts, 'LeftKeys')) + if (! isfield (opts, 'RightKeys')) error ('If option LeftKeys is supplied, then RightKeys must be, too.'); endif - if isnumeric (opts.LeftKeys) || islogical (opts.LeftKeys) - if islogical (opts.LeftKeys) + if (isnumeric (opts.LeftKeys) || islogical (opts.LeftKeys)) + if (islogical (opts.LeftKeys)) keyIxA = find (opts.LeftKeys); else keyIxA = opts.LeftKeys; endif keyNamesA = A.VariableNames(keyIxA); - elseif ischar (opts.LeftKeys) || iscellstr (opts.LeftKeys) + elseif (ischar (opts.LeftKeys) || iscellstr (opts.LeftKeys)) keyNamesA = cellstr (opts.LeftKeys); [tf, keyIxA] = ismember (keyNamesA, A.VariableNames); - if ! all (tf) + if (! all (tf)) error ('Named keys not found in table A: %s', strjoin (keyNamesA(!tf), ', ')); endif endif - if isnumeric (opts.RightKeys) || islogical (opts.RightKeys) - if islogical (opts.RightKeys) + if (isnumeric (opts.RightKeys) || islogical (opts.RightKeys)) + if (islogical (opts.RightKeys)) keyIxB = find (opts.RightKeys); else keyIxB = opts.RightKeys; endif keyNamesB = B.VariableNames(keyIxB); - elseif ischar (opts.RightKeys) || iscellstr (opts.RightKeys) + elseif (ischar (opts.RightKeys) || iscellstr (opts.RightKeys)) keyNamesB = cellstr (opts.RightKeys); [tf, keyIxB] = ismember (keyNamesB, B.VariableNames); - if ! all (tf) + if (! all (tf)) error ('Named keys not found in table B: %s', strjoin (keyNamesB(!tf), ', ')); endif endif - elseif isfield (opts, 'RightKeys') + elseif (isfield (opts, 'RightKeys')) error ('If option RightKeys is supplied, then LeftKeys must be, too.'); else # Default keys are a natural join @@ -1913,14 +1913,14 @@ function prettyprint (this) [~, keyIxA] = ismember (commonCols, A.VariableNames); [~, keyIxB] = ismember (commonCols, B.VariableNames); endif - if numel (keyIxA) != numel (keyIxB) + if (numel (keyIxA) != numel (keyIxB)) error ('Number of keys must be same for A and B; got %d vs. %s', ... numel (keyIxA), numel (keyIxB)); endif - if isfield (opts, 'LeftVariables') - if isnumeric (opts.LeftVariables) || islogical (opts.LeftVariables) - if islogical (opts.LeftVariables) + if (isfield (opts, 'LeftVariables')) + if (isnumeric (opts.LeftVariables) || islogical (opts.LeftVariables)) + if (islogical (opts.LeftVariables)) varIxA = find (opts.LeftVariables); else varIxA = opts.LeftVariables; @@ -1929,7 +1929,7 @@ function prettyprint (this) else varNamesA = cellstr (opts.LeftVariables); [tf, varIxA] = ismember (varNamesA, A.VariableNames); - if ! all (tf) + if (! all (tf)) error ('Named variables not found in table A: %s', strjoin (varNamesA(!tf), ', ')); endif endif @@ -1937,9 +1937,9 @@ function prettyprint (this) varIxA = 1:width(A); varNamesA = A.VariableNames; endif - if isfield (opts, 'RightVariables') - if isnumeric (opts.RightVariables) || islogical (opts.RightVariables) - if islogical (opts.RightVariables) + if (isfield (opts, 'RightVariables')) + if (isnumeric (opts.RightVariables) || islogical (opts.RightVariables)) + if (islogical (opts.RightVariables)) varIxB = find (opts.RightVariables); else varIxB = opts.RightVariables; @@ -1948,7 +1948,7 @@ function prettyprint (this) else varNamesB = cellstr (opts.RightVariables); [tf, varIxB] = ismember (varNamesB, B.VariableNames); - if ! all (tf) + if (! all (tf)) error ('Named variables not found in table B: %s', strjoin (varNamesB(!tf), ', ')); endif endif @@ -1986,24 +1986,24 @@ function prettyprint (this) ## @var{ixb} - Indexes into B for each row in out ## ## @end deftypefn - function [out, ixa, ixb] = innerjoin(A, B, varargin) + function [out, ixa, ixb] = innerjoin (A, B, varargin) # Input munging optNames = {'Keys', 'LeftKeys', 'RightKeys', ... 'LeftVariables', 'RightVariables'}; opts = peelOffNameValueOptions (varargin, optNames); - if ! istable (A) + if (! istable (A)) A = table (A); endif - if ! istable (B) + if (! istable (B)) B = table (B); endif - [out, ix] = realjoin(A, B, varargin{:}); + [out, ix] = realjoin (A, B, varargin{:}); ixa = ix(:,1); ixb = ix(:,2); endfunction - function [out, ixs] = realjoin(A, B, varargin) + function [out, ixs] = realjoin (A, B, varargin) #REALJOIN "Real" relational inner join, without key restrictions # # [out, ixs] = realjoin(A, B, varargin) @@ -2029,22 +2029,22 @@ function prettyprint (this) optNames = {'Keys', 'LeftKeys', 'RightKeys', ... 'LeftVariables', 'RightVariables'}; opts = peelOffNameValueOptions (varargin, optNames); - if ! istable (A) + if (! istable (A)) A = table (A); endif - if ! istable (B) + if (! istable (B)) B = table (B); endif opts2 = resolveJoinKeysAndVars (A, B, opts); - if hasrownames (A) + if (hasrownames (A)) error ('table.realjoin: Input A may not have row names'); endif - if hasrownames (B) + if (hasrownames (B)) error ('table.realjoin: Input B may not have row names'); endif # Join logic - if isempty (opts2.keyIxA) + if (isempty (opts2.keyIxA)) # This degenerates to a cartesian product [out, ixs] = cartesian (A, B); return @@ -2085,21 +2085,21 @@ function prettyprint (this) function [out, ixa, ixb] = outerjoin (A, B, varargin) # Input handling - if !istable (A) + if (! istable (A)) A = table (A); endif - if !istable (B) + if (! istable (B)) B = table (B); endif optNames = {'Keys', 'LeftKeys', 'RightKeys', 'MergeKeys', ... 'LeftVariables', 'RightVariables', 'Type'}; opts = peelOffNameValueOptions (varargin, optNames); - if isfield (opts, 'Type') + if (isfield (opts, 'Type')) joinType = opts.Type; else joinType = 'full'; endif - switch joinType + switch (joinType) case 'left' fillLeft = false; fillRight = true; @@ -2116,15 +2116,15 @@ function prettyprint (this) error ('table.outerjoin: Invalid opts.Type: %s', joinType); endswitch opts2 = resolveJoinKeysAndVars (A, B, opts); - if hasrownames (A) + if (hasrownames (A)) error ('table.outerjoin: Input A may not have row names'); endif - if hasrownames (B) + if (hasrownames (B)) error ('table.outerjoin: Input B may not have row names'); endif # Join logic - if isempty (opts2.keyIxA) + if (isempty (opts2.keyIxA)) # This degenerates to a cartesian product [out, ixs] = cartesian (A, B); return @@ -2141,7 +2141,7 @@ function prettyprint (this) ixa = ixs(:,1); ixb = ixs(:,2); fillTables = {}; - if fillLeft + if (fillLeft) fillRowB = outerfillvals (subB); fillLeftTable = [subsetrows(subA, ixUnmatchedA) ... repmat(fillRowB, [numel(ixUnmatchedA) 1])]; @@ -2149,7 +2149,7 @@ function prettyprint (this) ixa = [ixa; ixUnmatchedA]; ixB = [ixb; NaN(size(ixUnmatchedA))]; endif - if fillRight + if (fillRight) fillRowA = outerfillvals (subA); fillRightTable = [repmat(fillRowA, [numel(ixUnmatchedB) 1]) ... subsetrows(subB, ixUnmatchedB)]; @@ -2212,17 +2212,17 @@ function prettyprint (this) # together. # Input handling - if !istable (A) + if (! istable (A)) A = table (A); endif - if !istable (B) + if (! istable (B)) B = table (B); endif # Join logic keyVarNames = intersect_stable (A.VariableNames, B.VariableNames); nonKeyVarsB = setdiff_stable (B.VariableNames, keyVarNames); - if isempty (keyVarNames) + if (isempty (keyVarNames)) # The degenerate case of no common variable names is to keep all the rows. outA = A; ixA = 1:height (A); @@ -2235,7 +2235,7 @@ function prettyprint (this) [pkA, pkB] = proxykeysForMatrixes (keysA, keysB); ixA = find (ismember (pkA, pkB, 'rows')); outA = subsetrows (A, ixA); - if nargout > 2 + if (nargout > 2) ixB = find (ismember (pkB, pkA, 'rows')); outB = subsetrows (B, ixB); endif @@ -2261,17 +2261,17 @@ function prettyprint (this) function [outA, ixA, outB, ixB] = antijoin (A, B) # Input handling - if !istable (A) + if (! istable (A)) A = table (A); endif - if !istable (B) + if (! istable (B)) B = table (B); endif # Join logic keyVarNames = intersect_stable (A.VariableNames, B.VariableNames); nonKeyVarsB = setdiff_stable (B.VariableNames, keyVarNames); - if isempty (keyVarNames) + if (isempty (keyVarNames)) # The degenerate case when there are no common variable names is the empty set outA = subsetrows (A, []); ixA = []; @@ -2284,7 +2284,7 @@ function prettyprint (this) [pkA, pkB] = proxykeysForMatrixes (keysA, keysB); ixA = find (!ismember (pkA, pkB, 'rows')); outA = subsetrows (A, ixA); - if nargout > 2 + if (nargout > 2) ixB = find (!ismember (pkB, pkA, 'rows')); outB = subsetrows (B, ixB); endif @@ -2325,7 +2325,7 @@ function prettyprint (this) mustBeA (B, 'table'); commonVars = intersect (A.VariableNames, B.VariableNames); - if !isempty (commonVars) + if (! isempty (commonVars)) error ('table.cartesian: Inputs have variable names in common: %s', ... strjoin (commonVars, ', ')); endif @@ -2364,9 +2364,9 @@ function prettyprint (this) ## @end deftypefn function out = groupby (this, groupvars, aggcalcs) narginchk (2, 3); - if nargin < 3 || isempty (aggcalcs); aggcalcs = cell(0, 3); endif + if (nargin < 3 || isempty (aggcalcs)); aggcalcs = cell(0, 3); endif mustBeA (aggcalcs, 'cell'); - if size (aggcalcs, 2) != 3 + if (size (aggcalcs, 2) != 3) error ('table.groupby: aggcalcs must be an 3-wide cell; got %d-wide', ... size (aggcalcs, 2)); endif @@ -2389,7 +2389,7 @@ function prettyprint (this) agg_ins{i_in_var} = this.VariableValues{ix_in_vars(i_in_var)}(tf_in_group); endfor agg_out = fcn(agg_ins{:}); - if i_group == 1 + if (i_group == 1) agg_outs{i_agg} = repmat(agg_out, [n_groups 1]); else agg_outs{i_agg}(i_group,:) = agg_out; @@ -2413,18 +2413,18 @@ function prettyprint (this) ## @end deftypefn function out = grpstats (this, groupvar, varargin) [opts, args] = peelOffNameValueOptions (varargin, {'DataVars'}); - if numel (args) > 1 + if (numel (args) > 1) error ('table.grpstats: too many inputs'); - elseif numel (args) == 1 + elseif (numel (args) == 1) whichstats = args{1}; else whichstats = {'mean'}; endif - if ! iscell (whichstats) + if (! iscell (whichstats)) error ('whichstats must be a cell array'); endif [ix_groupvar, groupvar_names] = resolveVarRef (this, groupvar); - if isfield (opts, 'DataVars') + if (isfield (opts, 'DataVars')) data_vars = opts.DataVars; [ix_data_vars, data_vars] = resolveVarRef (this, data_vars); else @@ -2445,14 +2445,14 @@ function prettyprint (this) for i_var = 1:numel (data_vars) for i_stat = 1:numel (whichstats) - if ischar (whichstats{i_stat}) + if (ischar (whichstats{i_stat})) stat_fcn_name = whichstats{i_stat}; [tf,loc] = ismember (stat_fcn_name, stat_map(:,1)); - if ! tf + if (! tf) error ('table.grpstats: unsupported stat name: %s', stat_fcn_name); endif stat_fcn = stat_map{loc,2}; - elseif isa (whichstats{i_stat}, fcn_handle) + elseif (isa (whichstats{i_stat}, fcn_handle)) stat_fcn = whichstats{i_stat}; stat_fcn_name = func2str (stat_fcn); endif @@ -2514,17 +2514,17 @@ function prettyprint (this) 'DataVariables'}); for i = 1:width (this) - if size (this.VariableValues{i}, 2) > 1 + if (size (this.VariableValues{i}, 2) > 1) error ('table.rows2vars: Table variables may not have more than 1 column'); - elseif istable (this.VariableValues{i}) + elseif (istable (this.VariableValues{i})) error ('table.rows2vars: Nested tables are not supported'); endif endfor - if isfield (opts, 'VariableNamesSource') + if (isfield (opts, 'VariableNamesSource')) new_var_names = getvar (this, opts.VariableNamesSource); tbl = removevars (this, opts.VariableNamesSource); - elseif hasrownames (this) + elseif (hasrownames (this)) new_var_names = this.RowNames'; tbl = this; else @@ -2534,7 +2534,7 @@ function prettyprint (this) endfor tbl = this; endif - if isfield (opts, 'DataVariables') + if (isfield (opts, 'DataVariables')) tbl = subsetvars (tbl, opts.DataVariables); endif OriginalVariableNames = tbl.VariableNames(:); @@ -2542,12 +2542,12 @@ function prettyprint (this) col_types = cellfun (@(x) class(x), tbl.VariableValues); u_col_types = unique (col_types); - if isscalar (u_col_types) + if (isscalar (u_col_types)) matrix = cat (2, tbl.VariableValues{:}); else cols_as_cells = cell (1, width (tbl)); for i = 1:width (tbl) - if iscell (tbl.VariableValues{i}) + if (iscell (tbl.VariableValues{i})) cols_as_cells{i} = tbl.VariableValues{i}; else cols_as_cells{i} = num2cell (tbl.VariableValues{i}); @@ -2558,8 +2558,7 @@ function prettyprint (this) matrix = matrix'; new_var_values = num2cell (matrix, 1); - out = table(new_var_values{:}, ... - 'VariableNames', new_var_names); + out = table(new_var_values{:}, 'VariableNames', new_var_names); out = [tbl_original_var_names out]; endfunction @@ -2582,26 +2581,25 @@ function prettyprint (this) ## ## @end deftypefn function [outA, outB] = congruentize (A, B) - - if !istable (A) + if (! istable (A)) A = table (A); endif - if !istable (B) + if (! istable (B)) B = table (B); endif - if hasrownames (A) && !hasrownames (B) + if (hasrownames (A) && !hasrownames (B)) error ('table.congruentize: Input A has row names but input B does not'); endif - if !hasrownames (A) && hasrownames (B) + if (! hasrownames (A) && hasrownames (B)) error ('table.congruentize: Input B has row names but input A does not'); endif varsOnlyInA = setdiff (A.VariableNames, B.VariableNames); - if !isempty (varsOnlyInA) + if (! isempty (varsOnlyInA)) error ('table.congruentize: Input A has variables not present in B: %s', ... strjoin (varsOnlyInA, ', ')); endif varsOnlyInB = setdiff (B.VariableNames, A.VariableNames); - if !isempty (varsOnlyInB) + if (! isempty (varsOnlyInB)) error ('table.congruentize: Input B has variables not present in A: %s', ... strjoin (varsOnlyInB, ', ')); endif @@ -2610,7 +2608,6 @@ function prettyprint (this) outB = B; [~,loc] = ismember (A.VariableNames, outB.VariableNames); outB = subsetvars (outB, loc); - endfunction ## -*- texinfo -*- @@ -2759,13 +2756,13 @@ function prettyprint (this) function out = ismissing (this, indicator) mustBeA (this, 'table'); hasIndicator = false; - if nargin > 1 + if (nargin > 1) hasIndicator = true; endif mustBeAllColVectorVars (this); out = false (size (this)); for i = 1:width (this) - if hasIndicator + if (hasIndicator) out(:,i) = ismissing (this.VariableValues{i}, indicator); else out(:,i) = ismissing (this.VariableValues{i}); @@ -2794,25 +2791,25 @@ function prettyprint (this) [opts, args] = peelOffNameValueOptions (varargin, validOptions); unimplementedOptions = {'GroupingVariables', 'ErrorHandler'}; for i = 1:numel (unimplementedOptions) - if isfield (opts, unimplementedOptions{i}) + if (isfield (opts, unimplementedOptions{i})) error ('table.varfun: Option %s is not yet implemented.', unimplementedOptions{i}); endif endfor - if !isa (func, 'function_handle') + if (! isa (func, 'function_handle')) error ('table.varfun: func must be a function handle; got a %s', class (func)); endif outputFormat = 'table'; - if isfield (opts, 'OutputFormat') + if (isfield (opts, 'OutputFormat')) outputFormat = opts.OutputFormat; endif validOutputFormats = {'table','uniform','cell'}; - if !ismember (outputFormat, validOutputFormats); + if (! ismember (outputFormat, validOutputFormats)) error ('table.varfun: Invalid OutputFormat: %s. Must be one of: %s', ... outputFormat, strjoin (validOutputFormats, ', ')); endif errorHandler = []; - if isfield (opts, 'ErrorHandler') - if !isa (opts.ErrorHandler, 'function_handle') + if (isfield (opts, 'ErrorHandler')) + if (! isa (opts.ErrorHandler, 'function_handle')) error ('table.varfun: ErrorHandler must be a function handle; got a %s', ... class (opts.ErrorHandler)); endif @@ -2820,7 +2817,7 @@ function prettyprint (this) endif tbl = A; - if isfield (opts, 'InputVariables') + if (isfield (opts, 'InputVariables')) ixInVars = resolveVarRef (tbl, opts.InputVariables); else ixInVars = 1:width (tbl); @@ -2830,7 +2827,7 @@ function prettyprint (this) for i = 1:numel (ixInVars) ixInVar = ixInVars(i); varVal = tbl.VariableValues{ixInVar}; - if isempty (errorHandler) + if (isempty (errorHandler)) fcnOut = feval (func, varVal); else try @@ -2842,14 +2839,14 @@ function prettyprint (this) outVals{i} = fcnOut; endfor - switch outputFormat + switch (outputFormat) case 'cell' out = outVals; case 'table' out = table (outVals{:}, 'VariableNames', tbl.VariableNames); case 'uniform' tfScalar = cellfun('isscalar', outVals); - if !all (tfScalar) + if (! all (tfScalar)) ixFirstBad = find(!tfScalar, 1); error (['table.varfun: For OutputFormat ''uniform'', all function ' ... 'outputs must be scalar; output %d was %d long'], ... @@ -2857,7 +2854,7 @@ function prettyprint (this) endif outClasses = cellfun ('class', outVals, 'UniformOutput', false); uOutClasses = unique (outClasses); - if numel (uOutClasses) > 1 + if (numel (uOutClasses) > 1) error (['table.varfun: For OutputFormat ''uniform'', all function ' ... 'outputs must be the same type; got a mix of: %s'], ... strjoin (uOutClasses, ', ')); @@ -2939,25 +2936,25 @@ function prettyprint (this) [opts, args] = peelOffNameValueOptions (varargin, validOptions); unimplementedOptions = {'GroupingVariables'}; for i = 1:numel (unimplementedOptions) - if isfield (opts, unimplementedOptions{i}) + if (isfield (opts, unimplementedOptions{i})) error ('table.rowfun: Option %s is not yet implemented.', unimplementedOptions{i}); endif endfor - if !isa (func, 'function_handle') + if (! isa (func, 'function_handle')) error ('table.rowfun: func must be a function handle; got a %s', class (func)); endif output_format = 'table'; - if isfield (opts, 'OutputFormat') + if (isfield (opts, 'OutputFormat')) output_format = opts.OutputFormat; endif validOutputFormats = {'table','uniform','cell'}; - if !ismember (outputFormat, validOutputFormats); + if (! ismember (outputFormat, validOutputFormats)) error ('table.rowfun: Invalid OutputFormat: %s. Must be one of: %s', ... outputFormat, strjoin (validOutputFormats, ', ')); endif errorHandler = []; if isfield (opts, 'ErrorHandler') - if !isa (opts.ErrorHandler, 'function_handle') + if (! isa (opts.ErrorHandler, 'function_handle')) error ('table.rowfun: ErrorHandler must be a function handle; got a %s', ... class (opts.ErrorHandler)); endif @@ -2965,17 +2962,17 @@ function prettyprint (this) endif tbl = A; n_out_args = []; - if isfield (opts, 'NumOutputs') + if (isfield (opts, 'NumOutputs')) mustBeScalar (opts.NumOutputs, 'opts.NumOutputs'); mustBeNumeric (opts.NumOutputs, 'opts.NumOutputs'); n_out_args = opts.NumOutputs; endif - if isfield (opts, 'OutputVariableNames') + if (isfield (opts, 'OutputVariableNames')) out_var_names = opts.OutputVariableNames; n_out_args = numel (out_var_names); mustBeCellstr (out_var_names, 'opts.OutputVariableNames'); else - if isempty (n_out_args) + if (isempty (n_out_args)) n_out_args = 1; endif out_var_names = cell (1, n_out_args); @@ -2984,24 +2981,24 @@ function prettyprint (this) endfor endif do_separate_inputs = true; - if isfield (opts, 'SeparateInputs') + if (isfield (opts, 'SeparateInputs')) do_separate_inputs = opts.SeparateInputs; endif do_extract_cell_contents = false; - if isfield (opts, 'ExtractCellContents') + if (isfield (opts, 'ExtractCellContents')) mustBeScalarLogical (opts.ExtractCellContents, 'opts.ExtractCellContents'); do_extract_cell_contents = opts.ExtractCellContents; endif - if do_extract_cell_contents + if (do_extract_cell_contents) for i = 1:width (this) - if iscell (this.VariableValues{i}) && size (this.VariableValues{i}, 2) > 1 + if (iscell (this.VariableValues{i}) && size (this.VariableValues{i}, 2) > 1) error (['table.rowfun: Calling rowfun on a table with multi-column cell ' ... 'variables is not supported when ''ExtractCellContents'' is true' ... '(bad variable: %s)'], this.VariableNames{i}); endif endfor endif - if isfield (opts, 'InputVariables') + if (isfield (opts, 'InputVariables')) this = subsetvars (this, opts.InputVariables); endif @@ -3012,15 +3009,15 @@ function prettyprint (this) for i_row = 1:height (this) args = cell (1, n_vars); for i_var = 1:n_vars - if do_extract_cell_contents && iscell (vars{i_var}) + if (do_extract_cell_contents && iscell (vars{i_var})) args{i_var} = vars{i_var}{i_row}; else args{i_var} = vars{i_var}(i_row,:); endif endfor argouts = cell (1, n_out_args); - if do_separate_inputs - if isempty (errorHandler) + if (do_separate_inputs) + if (isempty (errorHandler)) [argouts{:}] = func (args{:}); else try @@ -3031,7 +3028,7 @@ function prettyprint (this) endif else single_input = [args{:}]; - if isempty (errorHandler) + if (isempty (errorHandler)) [argouts{:}] = func (single_input); else try @@ -3047,9 +3044,9 @@ function prettyprint (this) endfor # Output packaging - switch output_format + switch (output_format) case 'table' - out_vars = cellfun(@(c) cat(1, c{:}), out_bufs); + out_vars = cellfun (@(c) cat(1, c{:}), out_bufs); out = table (out_vars{:}, 'VariableNames', out_var_names); varargout = { out }; case 'cell' @@ -3115,7 +3112,7 @@ function prettyprint (this) ## ## @end deftypefn function out = evalWithVars (this, expr) - if !ischar (expr) + if (! ischar (expr)) error ('table.evalWithVars: expr must be char; got a %s', class (expr)); endif out = __eval_expr_with_table_vars_in_workspace__ (this, expr); @@ -3151,11 +3148,13 @@ function prettyprint (this) ## ## @end deftypefn function out = restrict (this, arg) - if ischar (arg) + if (ischar (arg)) rowIx = evalWithVars (this, arg); out = subsetrows (this, rowIx); - elseif isnumeric (arg) || islogical (arg) + elseif (isnumeric (arg) || islogical (arg)) out = subsetrows (this, arg); + else + error('restrict: invalid input type: %s', class (arg)) endif endfunction @@ -3180,12 +3179,12 @@ function prettyprint (this) ## Renames ## @end deftypefn function out = renamevars (this, renameMap) - if ! iscellstr (renameMap) || size (renameMap, 2) ~= 2 + if (! iscellstr (renameMap) || size (renameMap, 2) != 2) error ('renameMap must be an n-by-2 cellstr; got a %s %s', ... size2str (size (renameMap)), class (renameMap)); endif [tf,loc] = ismember (renameMap(:,1), this.VariableNames); - if ! all (tf) + if (! all (tf)) error ('No such variables in this: %s', strjoin (renameMap(!tf,1), ', ')); endif out = this; @@ -3245,31 +3244,31 @@ function prettyprint (this) # # A varRef is a numeric or char/cellstr indicator of which variables within # this table are being referenced. - if nargin < 3 || isempty (strictness); strictness = 'strict'; endif + if (nargin < 3 || isempty (strictness)); strictness = 'strict'; endif mustBeMember (strictness, {'strict','lenient'}); - if isnumeric (varRef) || islogical (varRef) + if (isnumeric (varRef) || islogical (varRef)) ixVar = varRef; ix_bad = find(ixVar > width (this) | ixVar < 1); - if ! isempty (ix_bad) + if (! isempty (ix_bad)) error ('table: variable index out of bounds: %d (table has %d variables)', ... ix_bad(1), width (this)); endif - elseif isequal (varRef, ':') + elseif (isequal (varRef, ':')) ixVar = 1:width (this); - elseif ischar (varRef) || iscellstr (varRef) + elseif (ischar (varRef) || iscellstr (varRef)) varRef = cellstr (varRef); [tf, ixVar] = ismember (varRef, this.VariableNames); - if isequal (strictness, 'strict') - if !all (tf) + if (isequal (strictness, 'strict')) + if (! all (tf)) error ('table: No such variable in table: %s', strjoin (varRef(!tf), ', ')); endif else ixVar(!tf) = 0; endif - elseif isa (varRef, 'tblish.internal.table.vartype_filter') + elseif (isa (varRef, 'tblish.internal.table.vartype_filter')) ixVar = []; for i = 1:width (this) - if varRef.matches (this.VariableValues{i}) + if (varRef.matches (this.VariableValues{i})) ixVar(end+1) = i; endif endfor @@ -3284,17 +3283,17 @@ function prettyprint (this) #RESOLVEROWVARREFS Internal implementation method # # This resolves both row and variable refs to indexes. - if isnumeric (rowRef) || islogical (rowRef) + if (isnumeric (rowRef) || islogical (rowRef)) ixRow = rowRef; - elseif iscellstr (rowRef) - if isempty (this.RowNames) + elseif (iscellstr (rowRef)) + if (isempty (this.RowNames)) error ('table: this table has no RowNames'); endif [tf, ixRow] = ismember (rowRef, this.RowNames); - if !all (tf) + if (! all (tf)) error ('table: No such named row in table: %s', strjoin (rowRef(!tf), ', ')); endif - elseif isequal (rowRef, ':') + elseif (isequal (rowRef, ':')) ixRow = 1:height (this); else error ('table: Unsupported row indexing operand type: %s', class (rowRef)); @@ -3316,7 +3315,7 @@ function prettyprint (this) ## @end deftypefn function out = subsetrows (this, ixRows) out = this; - if !isnumeric (ixRows) && !islogical (ixRows) + if (! isnumeric (ixRows) && !islogical (ixRows)) # TODO: Hmm. Maybe we ought not to do this check, but just defer to the # individual variable values' indexing logic, so SUBSREF/SUBSINDX overrides # are respected. Would produce worse error messages, but be more "right" @@ -3328,7 +3327,7 @@ function prettyprint (this) for i = 1:width (this) out.VariableValues{i} = subsref (out.VariableValues{i}, s); endfor - if !isempty (this.RowNames) + if (! isempty (this.RowNames)) out.RowNames = out.RowNames(ixRows); endif endfunction @@ -3351,14 +3350,14 @@ function prettyprint (this) ## ## @end deftypefn function out = subsetvars (this, ixVars) - if ischar (ixVars) - if !isequal (ixVars, ':') + if (ischar (ixVars)) + if (! isequal (ixVars, ':')) ixVars = cellstr (ixVars); endif endif - if iscellstr (ixVars) + if (iscellstr (ixVars)) [tf,ix] = ismember (ixVars, this.VariableNames); - if !all (tf) + if (! all (tf)) error ('table.subsetvars: no such variables in this table: %s', ... strjoin (ixVars(!tf), ', ')); endif @@ -3381,18 +3380,18 @@ function prettyprint (this) for i = 1:numel (namesB) oldName = namesB{i}; newName = []; - if ! isfield (seenNames, oldName) + if (! isfield (seenNames, oldName)) newName = oldName; else newBaseName = [oldName '_B']; - if ! isfield (seenNames, newBaseName) + if (! isfield (seenNames, newBaseName)) newName = newBaseName; else n = 0; - while true + while (true) n = n + 1; candidate = sprintf('%s_%d', newBaseName, n); - if ! isfield (seenNames, candidate) + if (! isfield (seenNames, candidate)) newName = candidate; break endif @@ -3409,7 +3408,7 @@ function prettyprint (this) function out = transpose_table (this) #TRANSPOSE_TABLE This is for table's internal use - if !hasrownames (this) + if (! hasrownames (this)) error ('table.transpose: this must have RowNames, but it does not'); endif c = table2cell (this); @@ -3419,12 +3418,12 @@ function prettyprint (this) function mustBeAllSameVars (varargin) #MUSTBEALLSAMEVARS Require that all inputs have the same-named columns args = varargin; - if isempty (args) + if (isempty (args)) return endif varNames = args{1}.VariableNames; for i = 2:numel (args) - if !isequal (varNames, args{i}.VariableNames) + if (! isequal (varNames, args{i}.VariableNames)) error ('Inconsistent VariableNames.\n Input 1: %s\n Input %d: %s', ... strjoin (varNames, ', '), i, strjoin (args{i}.VariableNames, ', ')); endif @@ -3435,7 +3434,7 @@ function mustBeAllColVectorVars (this) #MUSTBEALLCOLVECTORVARS Require that all vars in this are vectors, not matrixes for i = 1:width (this) val = this.VariableValues{i}; - if size (val, 2) ~= 1 + if (size (val, 2) != 1) error ('All variables in input must be vectors, but variable %d (''%s'') has %d columns', ... i, this.VariableNames{i}, size (val, 2)); endif @@ -3464,13 +3463,13 @@ function mustBeAllColVectorVars (this) # Note: This is called "proxykeysForMatrixes", not "proxyKeysForTables", because # it overrides the generic proxykeysForMatrixes, and tables *are* matrixes. - if nargin == 1 + if (nargin == 1) mustBeA (A, 'table'); pkA = proxykeysForOneTable (A); else mustBeA (A, 'table'); mustBeA (B, 'table'); - if width (A) != width (B) + if (width (A) != width (B)) error ('table.proxykeysForMatrixes: Tables must be same width; got %d vs %d', ... width (A), width (B)); endif @@ -3503,19 +3502,19 @@ function mustBeAllColVectorVars (this) # Summary stuff function summary_impl (this, format) - if nargin < 2 || isempty (format); format = 'compact'; endif + if (nargin < 2 || isempty (format)); format = 'compact'; endif infos = {}; for i_var = 1:width (this) infos{i_var} = summary_for_variable (this, i_var); endfor printf ("%s: %d %s by %d %s\n", class (this), height (this), this.DimensionNames{1}, ... width (this), this.DimensionNames{2}); - switch format + switch (format) case 'long' for i_var = 1:numel (infos) s = infos{i_var}; printf ("%d: %s\n", i_var, s.name); - if ! ismember (s.type, {"double", "string"}) + if (! ismember (s.type, {"double", "string"})) printf (" %s\n", s.type); endif val_col_width = max (cellfun(@numel, s.info(:,2))); @@ -3558,15 +3557,15 @@ function summary_impl (this, format) out.name = this.VariableNames{ix}; x = this.VariableValues{ix}; out.type = class (x); - if size (x, 2) > 1 + if (size (x, 2) > 1) out.info = { 'Columns' size(x, 2) }; - elseif isnumeric (x) + elseif (isnumeric (x)) out.info = summary_for_var_numeric (x); - elseif iscategorical (x) + elseif (iscategorical (x)) out.info = summary_for_var_categorical (x); - elseif isstring (x) || iscellstr (x) + elseif (isstring (x) || iscellstr (x)) out.info = summary_for_var_string (x); else out.info = cell (0, 2); @@ -3577,7 +3576,7 @@ function summary_impl (this, format) endclassdef function out = tablevar_dispstrs (x) - if isa (x, "string") + if (isa (x, "string")) out = cellstr (x); out(ismissing (x)) = {""}; else @@ -3590,11 +3589,11 @@ function summary_impl (this, format) n_cols = numel (strss); n_rows = max (cellfun (@numel, strss)); widths = NaN (1, n_cols); - for i = 1:numel(strss) + for i = 1:numel (strss) strss{i}(end+1:n_rows) = {''}; widths(i) = max (cellfun (@numel, strss{i})); - for j = 1:numel(strss{i}) - if numel(strss{i}{j}) < widths(i) + for j = 1:numel (strss{i}) + if (numel(strss{i}{j}) < widths(i)) strss{i}{j}(end+1:widths(i)) = ' '; endif endfor @@ -3627,7 +3626,7 @@ function summary_impl (this, format) n_ctgs = numel (u_ctgs); n_missing = numel (find (ismissing (x))); u_ctg_strs = dispstrs (u_ctgs); - if n_ctgs <= max_ctgs_to_list + if (n_ctgs <= max_ctgs_to_list) out = {}; for i = 1:numel (u_ctgs) out = [out; { diff --git a/inst/timezones.m b/inst/timezones.m index bcaaddb1..501a8557 100644 --- a/inst/timezones.m +++ b/inst/timezones.m @@ -65,7 +65,7 @@ ids = ids(:); areas = cell (size (ids)); for i = 1:numel (ids) - if any (ids{i} == '/') + if (any (ids{i} == '/')) area = regexprep (ids{i}, '/.*', ''); else area = ''; @@ -73,13 +73,13 @@ areas{i} = area; endfor - if nargin > 0 + if (nargin > 0) tf = strcmp (out.Area, area); ids = ids(tf); areas = areas(tf); endif - if octave_has_table + if (octave_has_table) out = table (ids, areas, 'VariableNames',{'Name','Area'}); else out = struct; @@ -88,9 +88,10 @@ endif if nargout == 0 - if octave_has_table - # This assumes you're using Tablicious's table implementation - prettyprint (out); + if (octave_has_table) + # This assumes you're using Tablicious's table implementation; prettyprint + # is nonstandard. + prettyprint (out) else fmt = ' %-32s %-20s\n'; fprintf (fmt, 'Name', 'Area'); @@ -106,7 +107,7 @@ function out = octave_has_table persistent cache - if isempty (cache) + if (isempty (cache)) try t = table; cache = isa (t, 'table'); diff --git a/inst/validators/mustBeA.m b/inst/validators/mustBeA.m index 563d4d7d..7e18adde 100644 --- a/inst/validators/mustBeA.m +++ b/inst/validators/mustBeA.m @@ -29,14 +29,14 @@ ## @end deftypefn function mustBeA (x, type, label) - if nargin < 3; label = []; endif - if isa (x, type) + if (nargin < 3); label = []; endif + if (isa (x, type)) return endif - if isempty (label) + if (isempty (label)) label = inputname (1); endif - if isempty (label) + if (isempty (label)) label = "input"; endif error ('%s must be of type %s; got %s', label, type, class (x)); diff --git a/inst/validators/mustBeCellstr.m b/inst/validators/mustBeCellstr.m index 4a5e508e..93c5ddb0 100644 --- a/inst/validators/mustBeCellstr.m +++ b/inst/validators/mustBeCellstr.m @@ -30,15 +30,15 @@ ## @end deftypefn function mustBeCellstr (x, label) - if nargin < 2; label = []; endif - if ! iscellstr (x) - if isempty (label) + if (nargin < 2); label = []; endif + if (! iscellstr (x)) + if (isempty (label)) label = inputname (1); endif - if isempty (label) + if (isempty (label)) label = "input"; endif - if iscell (x) + if (iscell (x)) el_classes = cellfun (@(e) {class (e)}, x); type_descr = sprintf ("cell array containing %s", strjoin (el_classes, ", ")); else diff --git a/inst/validators/mustBeCharvec.m b/inst/validators/mustBeCharvec.m index e30c977f..2a48e532 100644 --- a/inst/validators/mustBeCharvec.m +++ b/inst/validators/mustBeCharvec.m @@ -33,12 +33,12 @@ ## @end deftypefn function mustBeCharvec (x, label) - if nargin < 2; label = []; endif - if ! (ischar (x) && (isrow (x) || isequal (size (x), [0 0]))) - if isempty (label) + if (nargin < 2); label = []; endif + if (! (ischar (x) && (isrow (x) || isequal (size (x), [0 0])))) + if (isempty (label)) label = inputname (1); endif - if isempty (label) + if (isempty (label)) label = "input"; endif error ("%s must be a char row vector; got a %s %s", ... diff --git a/inst/validators/mustBeSameSize.m b/inst/validators/mustBeSameSize.m index adc8e384..861d5fc3 100644 --- a/inst/validators/mustBeSameSize.m +++ b/inst/validators/mustBeSameSize.m @@ -29,19 +29,19 @@ ## @end deftypefn function [a, b] = mustBeSameSize (a, b, labelA, labelB) - if nargin < 3; labelA = []; endif - if nargin < 4; labelB = []; endif - if ! isequal (size (a), size (b)) - if isempty (labelA) + if (nargin < 3); labelA = []; endif + if (nargin < 4); labelB = []; endif + if (! isequal (size (a), size (b))) + if (isempty (labelA)) label = inputname (1); endif - if isempty (labelA) + if (isempty (labelA)) label = "input 1"; endif - if isempty (labelB) + if (isempty (labelB)) label = inputname (2); endif - if isempty (labelB) + if (isempty (labelB)) label = "input 2"; endif error ("%s and %s must be the same size; got %s and %s", ... diff --git a/inst/validators/mustBeScalar.m b/inst/validators/mustBeScalar.m index f5da448b..80271ea1 100644 --- a/inst/validators/mustBeScalar.m +++ b/inst/validators/mustBeScalar.m @@ -28,12 +28,12 @@ ## @end deftypefn function mustBeScalar (x, label) - if nargin < 3; label = []; endif - if !isscalar (x) - if isempty (label) + if (nargin < 3); label = []; endif + if (! isscalar (x)) + if (isempty (label)) label = inputname (1); endif - if isempty (label) + if (isempty (label)) label = "input"; endif error ('%s must be scalar', label); diff --git a/inst/validators/mustBeScalarLogical.m b/inst/validators/mustBeScalarLogical.m index 0b6ff547..6520e28e 100644 --- a/inst/validators/mustBeScalarLogical.m +++ b/inst/validators/mustBeScalarLogical.m @@ -28,12 +28,12 @@ ## @end deftypefn function x = mustBeScalarLogical (x, label) - if nargin < 2; label = []; endif - if ! (isscalar (x) && islogical (x)) - if isempty (label) + if (nargin < 2); label = []; endif + if (! (isscalar (x) && islogical (x))) + if (isempty (label)) label = inputname (1); endif - if isempty (label) + if (isempty (label)) label = "input"; endif error ("%s must be a scalar logical; got a %s %s", ... diff --git a/inst/validators/mustBeVector.m b/inst/validators/mustBeVector.m index 1b9bded9..dfbb61e2 100644 --- a/inst/validators/mustBeVector.m +++ b/inst/validators/mustBeVector.m @@ -27,12 +27,12 @@ ## @end deftypefn function mustBeVector (x, label) - if nargin < 2; label = []; endif - if ! (isvector (x) || isequal (size (x), [0 0])) - if isempty (label) + if (nargin < 2); label = []; endif + if (! (isvector (x) || isequal (size (x), [0 0]))) + if (isempty (label)) label = inputname (1); endif - if isempty (label) + if (isempty (label)) label = "input"; endif error ("%s must be a vector; got a %s", ... diff --git a/inst/vecfun.m b/inst/vecfun.m index b9f1a2e7..c55914f9 100644 --- a/inst/vecfun.m +++ b/inst/vecfun.m @@ -38,5 +38,5 @@ n_dims = ndims (x); - error('vecfun: This function is not yet implemented. Sorry.'); + error ('vecfun: This function is not yet implemented. Sorry.'); endfunction diff --git a/inst/years.m b/inst/years.m index 03bace15..586234fd 100644 --- a/inst/years.m +++ b/inst/years.m @@ -46,7 +46,7 @@ # Note: years creates fixed-length years, which is probably not what you want. # To create a duration of calendar years (which account for actual leap days), # use calyears. - if isnumeric (x) + if (isnumeric (x)) out = duration.ofDays (double (x) * 365.2425); else error ('Invalid input: expected numeric or duration; got %s', class (x)); diff --git a/octave_tablicious_make_local.m b/octave_tablicious_make_local.m index 3ebef7fe..ce8c4f86 100644 --- a/octave_tablicious_make_local.m +++ b/octave_tablicious_make_local.m @@ -28,15 +28,15 @@ ## ## @end deftypefn -function octave_tablicious_make_local +function octave_tablicious_make_local () %OCTAVE_TABLICIOUS_MAKE_LOCAL Build the octfiles for this repo % % Call this function if you are working with a local copy of this repo instead % of installing it as a package. d = dir; - if ~ismember('octave_tablicious_make_local.m', {d.name}) - [my_dir,me] = fileparts(mfilename('fullpath')); - error(['You are calling this function from the wrong directory.\n' ... + if (! ismember('octave_tablicious_make_local.m', {d.name})) + [my_dir,me] = fileparts (mfilename ('fullpath')); + error (['You are calling this function from the wrong directory.\n' ... '%s needs to be run from the directory it lives in.\n' ... 'cd to %s and try again.'], ... me, my_dir);