数字で始まる列名列名の頭文字が数字になっていると、コードがそれを日付と誤認識してしまい、問題が発生してしまうコードがあります。列名を変更してこの問題を解決しようとしましたが、見た目が悪くなっています。また、列名を表すオブジェクトをChar(obj)文でラップしてもうまくいかないことが分かりました。この問題をより適切に解決する方法について、何かアドバイスはありますか?
dt = Current Data Table();
cnmes = dt << get column names( "string" );
For( j = 1, j <= N Items( cnmes ), j++,
if (Starts With( cnmes[j], "1" ) == 1 | Starts With( cnmes[j], "2" ) == 1 | Starts With( cnmes[j], "3" ) == 1| Starts With( cnmes[j], "4" ) == 1 | Starts With( cnmes[j], "5" ) == 1 | Starts With( cnmes[j], "6" ) == 1 | Starts With( cnmes[j], "7" ) == 1 | Starts With( cnmes[j], "8" ) ==1 | Starts With( cnmes[j], "9" ) == 1 | Starts With( cnmes[j], "0") == 1 ,
Column(cnmes[j]) << set name("_"||cnmes[j])
) );
自動化とスクリプトRe: 数字で始まる列名Column()関数を使用して、「cnmes」列名リスト内の列名を参照できます。列名をハードコードする場合は、次の例のように記述します。
// Report snapshot: Big Class - Graph Builder
Data Table( "Big Class" ) << Graph Builder(
Variables( X( :"1height"n ), Y( :"1height"n ) ),
Elements( Points( X, Y, Legend( 6 ) ), Smoother( X, Y, Legend( 7 ) ) )
);

names default to here(1);
dt =
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "$SAMPLE_DATA/Big Class.jmp" );
// Change column name: height → 1height
try(Data Table( "Big Class" ):height << Set Name( "1height" ));
// Change column name: weight → 3weight
try(Data Table( "Big Class" ):weight << Set Name( "3weight" ));
cnmes = dt << get column names( "string" );
Graph Builder(
Variables( X( column(cnmes[5])), Y( column(cnmes[4]) ) ),
Elements( Points( X, Y, Legend( 6 ) ), Smoother( X, Y, Legend( 7 ) ) )
);
Re: 数字で始まる列名名前はアルファベットかアンダースコアで始まる必要があるため、これらの問題が発生しています(スクリプトガイド > JSLビルディングブロック > JSL構文規則 > 名前) 。何をしているかに応じて、名前を変更するかどうか(txnelsonのオプションを参照)が異なります。名前を変更するには、例えば次のような正規表現を利用できます。
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(0),
Compress File When Saved(1),
New Column("1col", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("13col", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("0col", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("Column 4",
Numeric,
"Continuous",
Format("Best", 12),
Set Values([])
)
);
colnames = dt << Get Column Names("String");
For Each({colname}, colnames,
newname = Regex(colname, "^\d+.+", "_\0");
If(!IsMissing(newname),
Column(dt, colname) << Set Name(newname);
);
);