Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R_eval can't execute a R script in a whole #34

Open
AurelienPeter opened this issue Jul 27, 2023 · 0 comments
Open

R_eval can't execute a R script in a whole #34

AurelienPeter opened this issue Jul 27, 2023 · 0 comments
Assignees

Comments

@AurelienPeter
Copy link

Describe the bug
When GAMA runs a R script the lines are executed line by line.
A condition taking several lines is not considered as a whole, as each line is independant. Thus even if the condition is not fulfilled the lines will be executed.
Maybe there is a way to execute several lines at once?

To Reproduce
Steps to reproduce the behavior:
Write script.R:

value = 0
if(F){
  value = 1
}
print(paste("value:",value))
if(T){
  value = 2
}
print(paste("value:",value))

Run this model:

model R_in_Gama

global skills:[RSkill]{
	file Rcode <- text_file("myscript.R");
	init {
		// Try to use R tasks
		do startR;
		// Loop that takes each line of the R script and execute it.
		loop s over: Rcode.contents{
			unknown a <- R_eval(s);
			write a;
		}
	}
}

experiment Test_R_Task type: gui {
}

Output in GAMA:

[0.0]
[NULL ]
[1.0]
[NULL ]
R>[1]
R> "�ÿþCurrent value: 1�ÿþ"
R>

Current value: 1
[NULL ]
[2.0]
[NULL ]
R>[1]
R> "�ÿþCurrent value: 2�ÿþ"
R>

Current value: 2

Expected behavior
The value should not become 1 as the condition is false.
The if statement is placed in the previous line and is not considered in the next line which is executed.

Desktop:

  • OS: Windows 10
  • GAMA version: 1.9.2
@lesquoyb lesquoyb transferred this issue from gama-platform/gama.old Jul 27, 2023
@lesquoyb lesquoyb self-assigned this Aug 8, 2023
@lesquoyb lesquoyb removed this from GAMA 1.9.2 Aug 21, 2023
@lesquoyb lesquoyb moved this to Todo in GAMA 1.9.3 Aug 21, 2023
@lesquoyb lesquoyb removed this from GAMA 1.9.3 Dec 5, 2023
@lesquoyb lesquoyb moved this to Todo in GAMA 2024-11 Dec 5, 2023
@lesquoyb lesquoyb removed their assignment Jun 12, 2024
@lesquoyb lesquoyb removed this from GAMA 2024-11 Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants