Subscribe Bookmark RSS Feed

Pipeline question/discussion about the << Operator.

landon

Super User

Joined:

Jun 23, 2011

I've read in the manual (Scripting Guide, Ch 11) where it explains about 'Nesting and Precedence' and wondered if others would like to have an option that would act more like a pipeline operator (not unlike the %>% magrittr operator in R). So instead of having to nest your stacked messages with parentheses like

( (object<<message1) <<message2) <<message3

it would be more readable and naturally flow from left to right

object %>>% message1

           %>>% message2

           %>>% message3

2 REPLIES
landon

Super User

Joined:

Jun 23, 2011

to motivate... I wondered how others would script this R/magrittr example in JSL, where they explain:

Four operations are performed to arrive at the desired data set, and they are written in a natural order: the same as the order of execution. Also, no temporary variables are needed. If yet another operation is required, it is straight-forward to add to the sequence of operations wherever it may be needed.

the_data <-

  read.csv('/path/to/data/file.csv') %>%

  subset(variable_a > x) %>%

  transform(variable_c = variable_a/variable_b) %>%

  head(100)

Craige_Hales

Staff

Joined:

Mar 21, 2013

You could do this.  It might not be the best approach for future maintenance; a well named variable can clarify a lot.

dt=open("C:\Program Files\SAS\JMPPRO\13\Samples\Import Data\bigclass_L.txt")

  <<selectwhere(13<=:age<=15)<<invertRowSelection<<deleterows

  <<newcolumn("halfage",formula(age/2))

  <<selectwhere(row()<=10)<<invertRowSelection<<deleterows;

You can make the invertRowSelection go away by changing the selectWhere condition. 

This works because I picked messages that don't create a new object (like <<subset).  If <<subset is used, then additional parens are needed to make subsequent messages go to the new object.  Using subset may be faster than using delete.

Six months later, I'd rather maintain something a bit less monolithic:

allData = Open( "C:\Program Files\SAS\JMPPRO\13\Samples\Import Data\bigclass_L.txt" );

ageSubset = allData << selectwhere( 13 <= :age <= 15 ) << subset( selected rows( 1 ) );

tenRows = ageSubset << selectwhere( Row() <= 10 ) << subset( selected rows( 1 ) );

tenRows << New Column( "halfage", formula( age / 2 ) );

Close( allData, nosave );

Close( ageSubset, nosave );

Craige