[open] OpenSesame and R: works together?
Hello,
Can I use a script in OpenSesame where I
a.) run an expernal script between each item presentation
b.) which uses the last data point from a saved file
c) and import the output of that external script to define the new itemset?
Or in short: Can I export and import csv-data between each trail in order to manipulate my itemset?
I have no experience with python, but I think its nice. I heavily rely on R, this is why I ask.
I already found the rpy-extension for python. Would this do the trick?
Has anyone expierence using R during running experiments in OpenSesame?
Best
Comments
You mean that you want to alternate between presenting stimuli using the OpenSesame sketchpad and running Python code? Sure.
Yes, working with text data is trivial in Python, see e.g., http://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html
As I understand it rpy is for executing R code in a Python script. If you just want to use R for working with text data, it's probably easier to just use native Python functions for that.
Cheers!
Check out SigmundAI.eu for our OpenSesame AI assistant!
hi sebastiaan,
after playing a little around and finishing the tutorial, I think it is very cool.
One more question(s ;-) ): Can you give me an example how I can precisely address and change the variable set I defined via the GUI? What data structure uses it?
Or in general, how do I address such items?
As I understand so far I can easily address a variable "item" - if I created it - which can just give me the row line in the variable spread sheet. If I want to have some of those rows deleted based on the subjects response data, how do I do that?
Can I also see the complete code at once? Is the opensesame-code pre-compiled into python or any other language?
greets
the plastic
Glad you like it!
In an inline_script item, you set variables using
exp.set('my_var_name', 'my_value') self.experiment.set('my_var_name', 'my_value') # for 0.25 and beforeand get variables using
my_value = self.get('my_var_name')See also
I'm not sure I fully understand the question. You want to change the loop table while the experiment is running, is that correct? That's currently not possible. The easiest way to do something similar is probably by using the "Run if" statement of the sequence item to skip particular trials under some conditions. But I would need to know more details before I can say something specific.
Perhaps this thread is useful:
Yes, the script, which uses a simple custom syntax, can be viewed and edited by clicking on 'Show script editor' in the general tab of the experiment. For more information, see
Cheers!
Check out SigmundAI.eu for our OpenSesame AI assistant!
Okay, thank you very much for your help.
I think, I will be able to dodge this problem of not being able to change the trial table by simply building me a copy of it as an python object. In this I will hopefully be able to do my calculations. Then I want to copy it in every trial back to the variables of opensesame before it is presented to a participant and get my conditions then, to decide ether to skip presentation of that trial or not .
Sounds like a plan?
Best.
Yes, if I understand correctly, that would be a feasible approach.
Basically, you just insert an inline_script at the start of each trial to initialize the trial variables (using exp.set() statements). You will want to do this initialization in the prepare phase of the inline_script, so that it takes place as early as possible.
Cheers!
Check out SigmundAI.eu for our OpenSesame AI assistant!
Great, thanks!
Ah, yeah, I can use ScyPy for that, right? Is it build in and simply available by "import SciPy" or whatever casing?
Yep, if you need SciPy (which you might), you can just:
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hello,
I found some bugs:
Could not save file, because the script could not be generated. The following error occured: Error: Script error Description: Failed to instantiate module 'inline_script' as 'copy_table_inline_script': Error: Script error Description: Error parsing ' set _prepare "print self.get('noi')' in item 'copy_table_inline_script': No closing quotationIt seems to have something to do with the indent of lines, bit the error does not disappear even when the inline script is empty.
I see. What operating system and version of OpenSesame are you using?
Right, variable names cannot not start with a digit (that's not valid Python), but OpenSesame doesn't check for this and gives an ugly error. In 0.27 (currently under development) you will get a more intelligible error message.
Cheers!
Check out SigmundAI.eu for our OpenSesame AI assistant!
Mointain Lion and 0.26
I think it maybe has something to do with the script. it behave strange because when I start inserting some code, it first turns out as expected:
but sometime it changes to
especially if I only define the prepare-phase.
But as I said, I do not know if this is that, because even when I clear all the code in the script, the error still prevents me from saving my project....
note: the "_" are not displayed correctlty here, but it is correct in the code...
I think that you are correct: It probably has something to do with the way that end-of-lines are encoded on Mac OS. There was trouble with that before. I thought we fixed it, but apparently not!
I forwarded this discussion to a colleague who can test it on Mac OS, as I don't have a mac myself. For now, maybe it's convenient to know that you can use the external script plug-in, which has this icon:
This plug-in allows you to run external .py files, so you can probably get around this bug.
Thanks for bringing this to our attention!
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thanks.
Another easy workaround is not to leave any of the run or prepare phase empty, e.g. by writing something like
into these.
Right, I think this probleem is indeed partly caused by incorrect processing of newline characters. We'll have to look into a fix for this.