[1] 2
attr(,"match.length")
[1] 1
attr(,"index.type")
[1] "chars"
attr(,"useBytes")
[1] TRUE
Using Artificial Intelligence to Write Code
February 4, 2026
Documentation (some examples are included in this presentation)
Github Student Developer Pack gives you access to the Pro version.
Tells you that Copilot is active, opens some settings and options.
Also called “code completions”: shows up in the editor
Two options to accept suggestions:
Cmd + Right Arrow to accept part of the suggestionHover over the suggestion to see alternative suggestions. 
Copilot will use information in comments to provide suggestions.
You can open a chat interface to interact with the Copilot LLMs.
This is a standard-ish chat interface.
Allows for:
Two options to open the chat interface:
Ctrl + Cmd + I to open chat sidebarIn “Ask” mode, provides a traditional chat interface.
You can provide specific references to Copilot:
By default, Copilot uses the following for references
In “Agent” mode, Copilot can edit files directly and run some commands (with permissions).
By default, the model use is set to “Auto”.
The list of available models changes frequently.
Different models have different rates (some count more to your usage limit).
Being descriptive in your code can help Copilot provide better suggestions.
All of these will improve (1) Copilot and (2) your code.
github.copilot.chat.codeGeneration.useInstructionFiles in VS Code settings.github/copilot-instructions.mdNo guarantee that the code generated is correct
LLMs also like to suggest code that it has seen before.
Copilot will also suggest commit messages based on the changes you made.
Go to GitHub Copilot online: https://github.com/copilot
In pairs,
Each partner select a different model (e.g. GPT-X, Claude X.X, Gemini X)
Ask about a coding task or concept from the course
Compare the responses from the different models
Regular expressions are a powerful tool for working with text data.
This tool exists and works in a similar way in many programming languages.
After introducing regex, we will see how Copilot can help you implement this tool.
Regular expressions ask for a pattern to be matched in a string.
[1] 2
attr(,"match.length")
[1] 1
attr(,"index.type")
[1] "chars"
attr(,"useBytes")
[1] TRUE
grep()“Global Regular Expression Print”
This function will return the words with a positive match.
[1] "apple" "banana"
gsub()Another common use is to replace pattern matches.
[1] "mean gdp" "median gdp" "mean income" "median income"
This can be very useful for:
Special characters in regex pattern:
. any character^ start of string$ end of stringNumber of pattern to match
* zero or more of the preceding character+ one or more of the preceding character? zero or one of the preceding character{n} exactly n (some number) of the preceding characterCharacter classes
[abc] a, b, or c[a-z] any lowercase letter[A-Z] any uppercase letter[0-9] any digit[^abc] not a, b, or cEscape character
\ to escape special characters
\^ to match the character ^text <-
"If you have any questions about our services, please do not hesitate to contact our customer support team.
You can reach us at (123) 456-7890 for general inquiries. For technical support, please call (987) 654-3210.
Additionally, our sales department can be contacted at (555) 123-4567 for any questions related to new purchases or product information.
We are here to assist you with any needs you may have."
pattern <- "\\([0-9]{3}\\) [0-9]{3}-[0-9]{4}"
# Extract phone numbers
phone_numbers <- regmatches(text, gregexpr(pattern, text))If you want to match a pattern but not include part of it in the match, you can use look ahead and look behind.
(?=...)(?<=...)where ... is the pattern to match.
I find this very useful for separating out multi-variable names.
[[1]]
[1] "mean"
[[2]]
[1] "median"
[[1]]
[1] "gdp"
[[2]]
[1] "income"
If you do ever use regex in R, I recommend the stringr package.
We haven’t introduced packages yet, but stringr has intuitive functions for working with text data and regex.
AI is currently