Skip to content

Commit 4046240

Browse files
committed
Fix models failing CodeTests
1 parent d904699 commit 4046240

18 files changed

Lines changed: 174 additions & 185 deletions

Code Examples/Extensions Examples/sr/boxplot-example.nlogox

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
extensions [sr]
2020

21-
to activate-JavaGD-plot-device
21+
to activate-javagd-plot-device
2222
clear-all
2323
sr:setup
2424
sr:set-plot-device
@@ -37,8 +37,8 @@ to test
3737
set mylist fput random-normal 10 20 mylist
3838
]
3939

40-
; show the list in the Command Center
41-
print mylist
40+
; show the list in the Output widget
41+
output-print mylist
4242

4343
; send the list into a new R dataframe (with one column named v1)
4444
(sr:set-data-frame "df1" "v1" mylist)
@@ -88,12 +88,13 @@ end</code>
8888
<button x="18" y="240" height="35" disableUntilTicks="true" forever="false" kind="Observer" width="63">test</button>
8989
<button x="18" y="136" height="35" disableUntilTicks="false" forever="true" kind="Observer" width="63">r-idle</button>
9090
<button x="18" y="348" height="35" disableUntilTicks="true" forever="false" kind="Observer" width="63">test2</button>
91-
<button x="18" y="14" height="35" disableUntilTicks="false" forever="false" kind="Observer" width="189">activate-JavaGD-plot-device</button>
91+
<button x="18" y="14" height="35" disableUntilTicks="false" forever="false" kind="Observer" width="189">activate-javagd-plot-device</button>
9292
<button x="18" y="450" height="35" disableUntilTicks="true" forever="false" kind="Observer" width="73">dev-off</button>
9393
<note x="18" y="69" backgroundDark="0" fontSize="11" width="459" markdown="false" height="47" textColorDark="-1" textColorLight="-16777216" backgroundLight="0">activate this button, if you want to have the R plot window active (this will create an empty loop for R, that it will stay active). If you want to save the boxplot in a file without seeing it in the R window, you don't need this button.</note>
9494
<note x="18" y="191" backgroundDark="0" fontSize="11" width="459" markdown="false" height="29" textColorDark="-1" textColorLight="-16777216" backgroundLight="0"><![CDATA[this button will create a temp. list, send it to R and creates a boxplot (into the standard grafics output -> the R Plot Window).]]></note>
9595
<note x="18" y="295" backgroundDark="0" fontSize="11" width="459" markdown="false" height="33" textColorDark="-1" textColorLight="-16777216" backgroundLight="0">this button will create two temp. lists, put them both into one R data.frame and creates a boxplot over both columns.</note>
9696
<note x="18" y="403" backgroundDark="0" fontSize="11" width="459" markdown="false" height="27" textColorDark="-1" textColorLight="-16777216" backgroundLight="0">this button will close the graphics device (here: the plot window). But you can also just close the window.</note>
97+
<output x="532" y="215" height="61" fontSize="12" width="216"></output>
9798
</widgets>
9899
<info><![CDATA[## WHAT IS IT?
99100

Code Examples/Extensions Examples/sr/datafile-example.nlogox

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ turtles-own [test]
2323
to create-and-write-data
2424
clear-all
2525
sr:setup
26-
crt 30
26+
create-turtles 30
2727
[
2828
set xcor random-xcor
2929
set ycor random-ycor
@@ -48,8 +48,8 @@ to load-and-show-data
4848
let xypos (map [ [?1 ?2] -> list ?1 ?2 ] xc yc)
4949
5050
foreach xypos
51-
[ [?1] ->
52-
crt 1
51+
[ ?1 ->
52+
create-turtles 1
5353
[
5454
set xcor (item 0 ?1)
5555
set ycor (item 1 ?1)
@@ -61,7 +61,7 @@ end
6161
to write-data-with-vector-dataframe
6262
clear-all
6363
64-
crt 30
64+
create-turtles 30
6565
[
6666
set xcor random-xcor
6767
set ycor random-ycor

Code Examples/Extensions Examples/sr/diversity-example.nlogox

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ to calc-diversity
138138
;; save the diversity value into the corresponding patch-variables
139139
let counter 1
140140
foreach xylist
141-
[ [?1] ->
141+
[ ?1 ->
142142
ask patch (item 0 ?1) (item 1 ?1)
143143
[
144144
set speccount (sr:runresult (word "spec[" counter "]"))

Code Examples/Extensions Examples/sr/example1.nlogox

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ to test
2929
output-print " "
3030

3131
;; create a list in r from agentset
32-
crt 10
32+
create-turtles 10
3333
[
3434
set xcor random-xcor
3535
set ycor random-ycor

Code Examples/Extensions Examples/sr/interactiveShell.nlogox

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ to setup
2323
clear-all
2424
sr:setup
2525

26-
crt 10
26+
create-turtles 10
2727
[
2828
set xcor random-xcor
2929
set ycor random-ycor
@@ -34,7 +34,7 @@ to setup
3434
end
3535

3636

37-
to open-interactiveShell
37+
to open-interactiveshell
3838
; open interactiveShell
3939
sr:show-console
4040
end</code>
@@ -53,7 +53,7 @@ str(ag.df.glob)
5353
]]></note>
5454
<button x="16" y="14" height="35" disableUntilTicks="false" forever="false" kind="Observer" width="79">setup
5555
</button>
56-
<button x="8" y="254" height="35" disableUntilTicks="false" forever="false" kind="Observer" width="148">open-interactiveShell</button>
56+
<button x="8" y="254" height="35" disableUntilTicks="false" forever="false" kind="Observer" width="148">open-interactiveshell</button>
5757
<note x="8" y="302" backgroundDark="0" fontSize="11" width="363" markdown="false" height="56" textColorDark="-1" textColorLight="-16777216" backgroundLight="0"><![CDATA[Note: If you want to assign a variable into the global environment you could use in NetLogo the "<<-" operator, like x <<- 10.2
5858
]]></note>
5959
</widgets>

Code Examples/Extensions Examples/sr/linear_regression-example.nlogox

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ to setup
3232
;; create initial food sources on patches
3333
create-food-sources
3434
;; create 10 turtles with random initial memory of collected food items
35-
crt 10
35+
create-turtles 10
3636
[
3737
set xcor random-xcor
3838
set ycor random-ycor

Code Examples/Extensions Examples/sr/package-example.nlogox

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,9 @@ to test-pcf1
2929
sr:run "p <- pcf(simdat)"
3030
sr:run "K <- Kest(simdat)"
3131
sr:run "p2 <- pcf(K)"
32-
let pcf_r (sr:runresult "p2$pcf")
33-
let r (sr:runresult "p2$r")
34-
35-
let pcf (map [ [?1 ?2] -> list ?1 ?2 ] r pcf_r)
36-
32+
3733
clear-plot
38-
foreach pcf
39-
[ [?1] ->
40-
set-current-plot "pair correlation function"
41-
plotxy (item 0 ?1) (item 1 ?1)
42-
]
43-
34+
update-plots
4435
end
4536
4637
@@ -67,7 +58,7 @@ to test-pcf2
6758
;; Assigns an R-point-pattern from the locations of the turtles and calculates the pair correlation function.
6859
sr:run "library(spatstat)"
6960
70-
crt 20
61+
create-turtles 20
7162
[
7263
set xcor random-xcor
7364
set ycor random-ycor
@@ -85,26 +76,25 @@ to test-pcf2
8576
sr:run "p <- pcf(agppp)"
8677
sr:run "K <- Kest(agppp)"
8778
sr:run "p2 <- pcf(K)"
88-
let pcf_r (sr:runresult "p2$pcf")
89-
let r (sr:runresult "p2$r")
90-
91-
let pcf (map [ [?1 ?2] -> list ?1 ?2 ] r pcf_r)
9279
9380
clear-plot
94-
foreach pcf
95-
[ [?1] ->
96-
set-current-plot "pair correlation function"
97-
plotxy (item 0 ?1) (item 1 ?1)
98-
]
99-
81+
update-plots
10082
end]]></code>
10183
<widgets>
10284
<view x="400" wrappingAllowedX="true" y="10" frameRate="30.0" minPycor="0" height="433" showTickCounter="true" patchSize="13.0" fontSize="10" wrappingAllowedY="true" width="433" tickCounterLabel="ticks" maxPycor="32" updateMode="0" maxPxcor="32" minPxcor="0"></view>
10385
<note x="7" y="19" backgroundDark="0" fontSize="17" width="337" markdown="false" height="42" textColorDark="-1" textColorLight="-2674135" backgroundLight="0">R-Package "spatstat" has to be installed!</note>
10486
<button x="8" y="53" height="35" disableUntilTicks="false" forever="false" kind="Observer" width="82">test-pcf1</button>
10587
<plot x="9" autoPlotX="true" yMax="1.0" autoPlotY="true" yAxis="pcf(r)" y="100" xMin="0.0" height="255" legend="false" xMax="1.0" yMin="0.0" width="383" xAxis="r" display="pair correlation function">
10688
<setup></setup>
107-
<update></update>
89+
<update><![CDATA[let pcf_r (sr:runresult "p2$pcf")
90+
let r (sr:runresult "p2$r")
91+
92+
let pcf (map [ [?1 ?2] -> list ?1 ?2 ] r pcf_r)
93+
94+
foreach pcf
95+
[ ?1 ->
96+
plotxy (item 0 ?1) (item 1 ?1)
97+
]]]></update>
10898
<pen interval="1.0" mode="0" display="default" color="-16777216" legend="true">
10999
<setup></setup>
110100
<update></update>

Code Examples/Extensions Examples/sr/patchesToRMatrix.nlogox

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ to setup
2727
]
2828
end
2929
30-
to sendPatchesToR
30+
to send-patches-to-r
3131
; send patches color to data.frame
3232
(sr:set-agent-data-frame "patches" patches "pxcor" "pycor" "pcolor")
3333
end
3434
35-
to createMatrix
35+
to create-matrix
3636
; get worlds dimension and send it to R
3737
sr:set "xdim" world-width
3838
; create matrix from data.frame column pcolor
@@ -48,8 +48,8 @@ end]]></code>
4848
<widgets>
4949
<view x="210" wrappingAllowedX="true" y="10" frameRate="30.0" minPycor="0" height="96" showTickCounter="true" patchSize="30.8" fontSize="10" wrappingAllowedY="true" width="158" tickCounterLabel="ticks" maxPycor="2" updateMode="0" maxPxcor="2" minPxcor="-2"></view>
5050
<button x="7" y="21" height="35" disableUntilTicks="false" forever="false" kind="Observer" width="63">setup</button>
51-
<button x="7" y="64" height="35" disableUntilTicks="false" forever="false" kind="Observer" width="124">sendPatchesToR</button>
52-
<button x="8" y="108" height="35" disableUntilTicks="false" forever="false" kind="Observer" width="162" display="create and show matrix">createMatrix</button>
51+
<button x="7" y="64" height="35" disableUntilTicks="false" forever="false" kind="Observer" width="124">send-patches-to-r</button>
52+
<button x="8" y="108" height="35" disableUntilTicks="false" forever="false" kind="Observer" width="162" display="create and show matrix">create-matrix</button>
5353
</widgets>
5454
<info><![CDATA[## WHAT IS IT?
5555

Code Examples/Extensions Examples/sr/plot-example1.nlogox

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ to setup
2222
clear-all
2323
sr:setup
2424
25-
crt 10
25+
create-turtles 10
2626
[
2727
set xcor random-xcor
2828
set ycor random-ycor

Code Examples/Extensions Examples/sr/plot-to-file-example.nlogox

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,24 @@ extensions [sr]
2121
to test-plot
2222
clear-all
2323
sr:setup
24-
crt 10
24+
create-turtles 10
2525
[
2626
set xcor random-xcor
2727
set ycor random-ycor
2828
]
2929

3030
(sr:set-agent "agentlist" turtles "who" "xcor" "ycor")
31-
print "create a plot into file..."
3231

3332
;; create a pdf with the plot
3433
let evalstring (word "pdf('" plotfile ".pdf')" )
35-
show evalstring
34+
3635
sr:run evalstring
3736
sr:run "plot(agentlist$xcor,agentlist$ycor)"
3837
sr:run "dev.off()"
3938

4039
;; create a jpeg with the plot
4140
set evalstring (word "jpeg('" plotfile ".jpeg')" )
42-
show evalstring
41+
4342
sr:run evalstring
4443

4544
sr:run "plot(agentlist$xcor,agentlist$ycor)"

0 commit comments

Comments
 (0)