[1] 2
attr(,"match.length")
[1] 1
attr(,"index.type")
[1] "chars"
attr(,"useBytes")
[1] TRUE
Using Artificial Intelligence to Write Code
February 5, 2025
Documentation (some examples are included in this presentation)
The Github Student Developer Pack gives you access to the Pro version of Copilot.
Tells you that Copilot is active, opens some settings and options.
Cmd + Right Arrow
to accept part of the ghost textHover over the ghost text to see alternative suggestions.
Copilot will use information in comments to provide suggestions.
Cmd + I
to open inline chatCtrl + Cmd + I
to open chat sidebarChat sidebar provides more “traditional” interface.
You can see Copilot in other places in VS Code.
Whenever you see the sparkle icon, Copilot can be used to help you.
Click on the sparkle icon to see what Copilot can do.
Copilot will provide suggestions for fixing the error.
From Github Copilot documentation, three ‘S’ principle for prompts:
You can provide context to Copilot with…
@workspace
@github
@vscode
@terminal
You can provide specific references to Copilot with…
#file
#editor
#selection
i.e. what is highlighted#terminalLastCommand
There are some common commands that can be used with…
/fix
/explain
/new
/help
/clear
By default, Copilot uses the following for references
Being descriptive in your code can help Copilot provide better suggestions.
All of these will improve (1) Copilot and (2) your code.
Different models have different use limits (depending on your Github subscription). The details of which are changing quite frequently as new models are developed.
github.copilot.chat.codeGeneration.useInstructionFiles
in VS Code settings.github/copilot-instructions.md
GitHub Documentation & Example File Content
We use Bazel for managing our Java dependencies, not Maven, so when talking about Java packages, always give me instructions and code samples that use Bazel.
We always write JavaScript with double quotes and tabs for indentation, so when your responses include JavaScript code, please follow those conventions.
Our team uses Jira for tracking items of work.
Regular expressions are a powerful tool for working with text data.
This tool exists and works in a similar way in many programming languages.
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.
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.
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
If you can access the online version, try it out!