Diff of /inst/@dataframe/subsasgn.m [afaced] .. [591ef1] Maximize Restore

  Switch to unified view

a/inst/@dataframe/subsasgn.m b/inst/@dataframe/subsasgn.m
...
...
40
        case "rownames"
40
        case "rownames"
41
          if (~isnull (RHS) && isempty (df._name{1}))
41
          if (~isnull (RHS) && isempty (df._name{1}))
42
            df._name{1}(1:df._cnt(1), 1) = {''};
42
            df._name{1}(1:df._cnt(1), 1) = {''};
43
            df._over{1}(1, 1:df._cnt(1)) = true;
43
            df._over{1}(1, 1:df._cnt(1)) = true;
44
          endif
44
          endif
45
          [df._name{1}, df._over{1}] = df_strset \
45
          [df._name{1}, df._over{1}] = df_strset ...
46
              (df._name{1}, df._over{1}, S(2:end), RHS);
46
              (df._name{1}, df._over{1}, S(2:end), RHS);
47
          return
47
          return
48
48
49
        case "rowidx"
49
        case "rowidx"
50
          if (1 == length (S))
50
          if (1 == length (S))
...
...
54
          endif
54
          endif
55
          return
55
          return
56
          
56
          
57
        case "colnames"
57
        case "colnames"
58
          if (isnull(RHS)) error ("Colnames can't be nulled"); endif
58
          if (isnull(RHS)) error ("Colnames can't be nulled"); endif
59
          [df._name{2}, df._over{2}] = df_strset \
59
          [df._name{2}, df._over{2}] = df_strset ...
60
              (df._name{2}, df._over{2}, S(2:end), RHS, '_');
60
              (df._name{2}, df._over{2}, S(2:end), RHS, '_');
61
          df._name{2} = genvarname (df._name{2});
61
          df._name{2} = genvarname (df._name{2});
62
          return
62
          return
63
          
63
          
64
        case "types"
64
        case "types"
...
...
67
            %# perform explicit cast on each column
67
            %# perform explicit cast on each column
68
            switch (RHS)
68
            switch (RHS)
69
              case {'char'}
69
              case {'char'}
70
                for indj = (1:df._cnt(2))
70
                for indj = (1:df._cnt(2))
71
                  if (isnumeric (df._data{indj}) || islogical (df._data{indj}))
71
                  if (isnumeric (df._data{indj}) || islogical (df._data{indj}))
72
                    df._data(indj) = cellfun (@(x) cellstr (num2str(x, "%f")), \
72
                    df._data(indj) = cellfun (@(x) cellstr (num2str(x, "%f")), ...
73
                                              df._data(indj), 
73
                                              df._data(indj), 
74
                                              "UniformOutput", false); 
74
                                              "UniformOutput", false); 
75
                  endif
75
                  endif
76
                endfor
76
                endfor
77
              otherwise
77
              otherwise
...
...
87
            endif 
87
            endif 
88
            if (length (S) > 2 || length (S(2).subs) > 1)
88
            if (length (S) > 2 || length (S(2).subs) > 1)
89
              error("Types can only be changed as a whole");
89
              error("Types can only be changed as a whole");
90
            endif
90
            endif
91
            if (~isnumeric(S(2).subs{1}))
91
            if (~isnumeric(S(2).subs{1}))
92
              [indj, ncol, S(2).subs{1}] = df_name2idx\
92
              [indj, ncol, S(2).subs{1}] = df_name2idx...
93
                  (df._name{2}, S(2).subs{1}, df._cnt(2), 'column');
93
                  (df._name{2}, S(2).subs{1}, df._cnt(2), 'column');
94
            else
94
            else
95
              indj = S(2).subs{1}; ncol = length (indj);
95
              indj = S(2).subs{1}; ncol = length (indj);
96
            endif
96
            endif
97
            switch (RHS)
97
            switch (RHS)
98
              case {'char'}
98
              case {'char'}
99
                if (isnumeric (df._data{indj}) || islogical (df._data{indj}))
99
                if (isnumeric (df._data{indj}) || islogical (df._data{indj}))
100
                  df._data(indj) = cellfun (@(x) cellstr (num2str(x, "%f")), \
100
                  df._data(indj) = cellfun (@(x) cellstr (num2str(x, "%f")), ...
101
                                            df._data(indj), 
101
                                            df._data(indj), 
102
                                            "UniformOutput", false); 
102
                                            "UniformOutput", false); 
103
                endif
103
                endif
104
              otherwise
104
              otherwise
105
                df._data(indj) = cellfun (@(x) cast (x, RHS), df._data(indj), 
105
                df._data(indj) = cellfun (@(x) cast (x, RHS), df._data(indj), 
...
...
136
        otherwise
136
        otherwise
137
          if (~ischar (S(1).subs))
137
          if (~ischar (S(1).subs))
138
            error ("Congratulations. I didn't see how to produce this error");
138
            error ("Congratulations. I didn't see how to produce this error");
139
          endif
139
          endif
140
          %# translate the name to column
140
          %# translate the name to column
141
          [indc, ncol] = df_name2idx (df._name{2}, S(1).subs, \
141
          [indc, ncol] = df_name2idx (df._name{2}, S(1).subs, ...
142
                                      df._cnt(2), 'column', true);
142
                                      df._cnt(2), 'column', true);
143
          if (isempty (indc))
143
          if (isempty (indc))
144
            %# dynamic allocation
144
            %# dynamic allocation
145
            df = df_pad (df, 2, 1, class (RHS));
145
            df = df_pad (df, 2, 1, class (RHS));
146
            indc = df._cnt(2); ncol = 1;
146
            indc = df._cnt(2); ncol = 1;
...
...
168
                S(2).subs = {'', indc, [1:size(RHS, 2)]};
168
                S(2).subs = {'', indc, [1:size(RHS, 2)]};
169
              endif
169
              endif
170
            endif
170
            endif
171
          endif
171
          endif
172
          %# do we need to "rotate" RHS ?
172
          %# do we need to "rotate" RHS ?
173
          if (1 == ncol && ndims (RHS) < 3 \
173
          if (1 == ncol && ndims (RHS) < 3 ...
174
                && size (RHS, 2) > 1)
174
                && size (RHS, 2) > 1)
175
            RHS = reshape (RHS, [size(RHS, 1), 1, size(RHS, 2)]);
175
            RHS = reshape (RHS, [size(RHS, 1), 1, size(RHS, 2)]);
176
          endif
176
          endif
177
          df = df_matassign (df, S(2), indc, ncol, RHS);
177
          df = df_matassign (df, S(2), indc, ncol, RHS);
178
      endswitch
178
      endswitch
179
      
179
      
180
    case '()'
180
    case '()'
181
      [indr, nrow, S(1).subs{1}] = df_name2idx (df._name{1}, S(1).subs{1}, \
181
      [indr, nrow, S(1).subs{1}] = df_name2idx (df._name{1}, S(1).subs{1}, ...
182
                                                df._cnt(1), 'row');
182
                                                df._cnt(1), 'row');
183
      if (isempty (indr) && df._cnt(1) > 0)
183
      if (isempty (indr) && df._cnt(1) > 0)
184
        %# this is not an initial assignment
184
        %# this is not an initial assignment
185
        df = df; return;
185
        df = df; return;
186
      endif
186
      endif
187
      
187
      
188
      if (length (S(1).subs) > 1)
188
      if (length (S(1).subs) > 1)
189
        if (~isempty (S(1).subs{2}))
189
        if (~isempty (S(1).subs{2}))
190
          [indc, ncol, S(1).subs{2}] = \
190
          [indc, ncol, S(1).subs{2}] = ...
191
              df_name2idx (df._name{2}, S(1).subs{2}, df._cnt(2), 'column');
191
              df_name2idx (df._name{2}, S(1).subs{2}, df._cnt(2), 'column');
192
          %# if (isempty (indc) && df._cnt(2) > 0)
192
          %# if (isempty (indc) && df._cnt(2) > 0)
193
          %# this is not an initial assignment
193
          %# this is not an initial assignment
194
          %# df = df; return;
194
          %# df = df; return;
195
        else
195
        else