2024-01-01
But this is an awful way to code!
Combines
Usually you get some other perks:
The welcome screen provides many useful quick links.
See that the welcome page is a tab and can be closed (leave it open for now).
On the left-hand side, we have the activity bar, where we can toggle different views.
The first is the Explorer, which shows files and subfolders, if you have a folder open.
Opening a new folder called “temp”, we can see that it is empty.
By clicking the “+ document” icon, we can create a new file and give it a name.
By clicking the “+ folder” icon, we can create a new subfolder and give it a name.
By clicking on a file, we can open it in the editor space.
Creating a couple more files, we can see that we can open all three in the editor space.
Dragging the third file tab to the right hand side, we can create a split editor view.
You can split the editor many times.
Drag a file off the window to create a new window (useful for multiple monitors).
The second activity bar icon is a Search tool, which searchs across all project documents.
The third activity bar icon is the Source Control tool. Let’s initialize a repository with it.
It immediately notices all five of my files. Hit the “+” to stage them.
Write a useful message and hit the commit button.
If we had a linked Github repository, we would now see a “Sync Changes” button.
The third activity bar icon is the Debugger. We won’t use this for now.
The fourth activity bar icon is for Extensions. You should see the R extension you installed.
This is where you can search for and install new extensions or uninstall them.
The final activity bar icon is for R. This was added when you installed the R extension.
It doesn’t show much at the moment, but if we add and run a simple R script…
It shows the variable x
has the value 4
. We will talk more about R next class.
At the bottom of the activity bar is a gear for Settings.
Command Palette...
opens the command paletteSettings
opens tab for all settings for VS CodeKeyboard Shortcuts
customize keyboard shortcutsThemes
customize the theme (colors) for your VS CodeIt contains all possible commands for VS Code.
This makes it very convenient.
To open…
You can almost always avoid using the command palette by clicking some buttons, but its easier to write directions that say run X command in the command palette than to say “click A, then B, then C”. In the long run its easier for you too!
Opens as an empty field at the top with a dropdown of recently used commands.
First, lets run Terminal: Create New Terminal
.
First, lets run Terminal: Create New Terminal
.
This opens a new pane at the bottom of the window with our terminal.
With this we can write commands to the computer, i.e. ls
to list all the files and folders.
With this we can write commands to the computer, i.e. ls
to list all the files and folders.
Back to the Command Palette, let’s start a new R terminal.
And this launches a new terminal at the bottom of the screen, but with R running.
Notice that we now have a second tab on the right side of the terminal pane…
If we drag that space bigger, we can see the labels for each tab. The “zzh” terminal is our one from earlier!
Click on a terminal to switch between them. Also notice the trash can to delete them.
You can create multiple R terminals. This is useful if you have code that takes a long time.
If you don’t have any R terminals open and run some code, VS Code will start one for you.
You can always run an entire script by hitting the “Play” button at the top right of an R file.
You can always run an entire script by hitting the “Play” button at the top right of an R file.
I much prefer to run code line by line with:
You can also highlight many lines of code and run just those with the same shortcut.
Visual Studio Code provides us both (1) an editor and (2) a terminal.
This is a good question. Most R users use Rstudio.
VS Code has…
I can’t enforce using VS Code for this class, but it is what I am assuming everyone is using.
Workspaces allow VS Code to…
When you open a single “folder”, VS Code automatically treats that as a workspace.
You will often see “folder” and “workspace” used interchangeably in VS Code documentation because of this. Technically, you can have multiple folders open in a workspace, but we will not be doing that.
Our practice VS Code folder “temp” was opened as a workspace.
We can change settings just for a specific workspace.
If we change a setting (say the theme) that is applied only to this workspace.
And a new “.vscode” folder is created to save these settings.
If you are coming from Rstudio, then workspaces are similar to R projects (.Rproj files).
A basic text file has the extension “.txt”
This tells the computer that this file just has “plain” text
Here is some plain text.
We could put this in a file with a ".txt" extension
Most coding files also just store plain text.
## This could be saved as a ".txt"
print("Hello World")
Adding a file extension, like “.r”,
tells the computer that file is R code.
You generally should not do this. You can break things.
But what if change the file extension of a “.pdf” to a “.txt”?
Well then we can open it in a text editor and see…
%PDF-1.5
%–‘≈ÿ
10 0 obj
<< /S /GoTo /D [11 0 R /Fit] >>
endobj
71 0 obj
<<
/Length 1322
/Filter /FlateDecode
>>
stream
x⁄ÌZKo9æ˚WË¥∞Vı~Ï≠[§≈ÿn„‰VÏ!;yç̃I∞Ëø_R3í∆c'éùÿuà5¢HJ$?r§ôa‰ä0Ú©«:-áñC{F§‘IMÑîCʉ≤wº$¥qK©ˇ-ô_ëvwÙ≥¥F√óµGöÁj≈î ¢≥8RRÈ°‘*G™IÔéÙñÿ…
File extensions tell the computer (and other people) what format the data in the file is using.
Some formats, like PDFs, PNGs, are very far from plain text.
Others, like coding files, are plain text
and are just telling the computer what syntax highlighting should be used and what software should be called to run it.
Markdown is an “easy-to-read” and “easy-to-write” langauge for formatting plain text.
It is like LaTeX, but with an emphasis on easy to read code.
You’ll see this extension on Github’s Readme documents: “README.md”
Github allows you to format some important documents with Markdown:
For today, we will be editing README files.