Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
How do I use %default_mode in a Sage worksheet?
Setting mode one cell at a time
Suppose you are using a Sage worksheet (.sagews file) in CoCalc and want to run commands in another interpreter or language such as
You can run gap commands in a single cell by doing the following:
%gap G:=Group([(99,100)]); IsTransitive(G);
and you can run
r commands in a cell the same way:
%r summary(iris) str(iris)
If most of the cells in your worksheet use something other than Sage, you can set a default_mode for the worksheet. Note:
- The cell with the %default_mode command must be executed before the mode is in effect.
- Start using the new mode in subsequent cells. Do not put calculation statements in the new mode in the cell that sets
After setting a default mode, you can temporarily override it in any cell using any of the usual %-commands.
Here's an example setting default mode, using it in two cells, and then running a cell in another mode:
# run this line by itself before running other cells %default_mode gap --- cell runs in gap mode--- G:=Group([(99,100)]); IsTransitive(G); --- another gap cell --- a:= (9 - 7) * (5 + 6); --- run a sage command while default mode is gap --- %sage factor(2018)
Setting default mode automatically with %auto
If you make
%auto the first line of a cell in a .sagews, that cell is executed whenever the worksheet is opened. A common situation when using a default mode is to set that mode automatically, as follows:
%auto %default_mode r
Note that you will have to execute this cell manually if you have just typed it in or restart the worksheet, for it to take effect.
Find out more
For more information on .sagews modes, including how to create your own custom modes (which is surprisingly easy!), see sagews custom modes.