Can't type in the script window-newbie question


#1

Newbie here. Been writing R (really S & S+) on and off for 30 years. New to Rstudio. I place my cursor in the scripts window and I can’t type anything. All of the youtube tutorials assume you can just place your cursor and type. I can navigate in the window and run code, but not enter or paste anything. I tried hitting the insert key and various things, no help. Surely, this is a simple problem. Thanks!


#2

I personally am unlikely to be able to help you with this, but I’m pretty sure some system info will be handy for troubleshooting (OS, RStudio version, special keybindings, etc).! Good luck.


#3

Windows 7, i7, 12 gigs ram, latest versions of Rstudio and R, no special keybindings or anything like that, that I know of. Thanks!


#4

My best advice:

(And that’s serious – go through a full reboot)

Other than that, you could try reinstalling RStudio and resetting its state:

Also, if you can take a screenshot of the difficulty, it’s possible that will trigger something else.


#5

Maybe dumb question/suggestion: did you already do file - > new_file - > r script from the. Top Menu to create a new script?


#6

Aha! That’s the problem. I was clicking on a function in the environment window. That opens the file, but apparently not for editing. This runs a function view(myfunction), which obviously is for view only. If I try edit(myfunction) it opens it for editing in a separate window. Now the only remaining question is how to edit it in the script window?


#7

To open an existing file open it from the files tab.

To open a new script file use the file command.

image

If you make an RStudio project it will set all this stuff up for you and keep track of a project directory for you.

In the dropdown from the file command select “new project” instead of new file.

Or to directly open a file without using the files tab use “open file” from the file drop down.


#8

You might want to check out the RStudio IDE Cheat sheet here on the cheat sheets page. Sounds like @danr has you covered for this one.


#9

Thanks to both of y’all, problem solved. I have functions (done in R) that don’t end in .R. These show up in the environment window but are not available as independent files in the working directory. I don’t understand how this all works–are the visible “.R” files copies of the functions in .Rdata with a different file format, or are they pointers to binaries in .Rdata?

Practically, I can simple make copies to solve the problem:
myfunction.R=myfunction #OOPS! This doesn’t work…any ideas? I mean it assigns, but the function is not showing up in my directory.

On this topic, I have tons of S functions that I would like to see. These are apparently binaries in a different file format. I found that there is a reading package that reads SPSS etc. that also has a read.S function: is this the best approach? Thanks in advance.


#10

Files like test.R file are just an ordinary text files that contains an R scripts.

.RData is a file that has no name, i.e. it is just an extension. It holds the state of a session. RStudio uses a session to keep track of variables and other internals as you do interactive operations with it. The
Environment tab in RStudio is shows the content of the .RData file.

image


#11

Yes, but since the files in .RData don’t show up when I use the open command, how do I edit them in the script window?


#12

Functions aren’t files, and defining a new function doesn’t automatically put it in a file. If you have a function that you can currently run in R that you have defined, it is probably getting saved to .Rdata when you exit, but that’s not really something you want to count on. Instead, you need to start a new script, like “my_functions.R”, and copy and paste the code for the functions into that file.


#13

OK, got it. Different working style than I’m used to in plain R, but that’s fine. Thanks…I’ve been waiting 30 years for something like Rstudio!..I started with S, then “new S,” then S+, and so forth.