Video Notes
In the above video, I walk through importing and processing a dataset using R while working in Positron. Along the way, I highlight several of Positron’s features, including its built-in AI capabilities, and share practical tips and best practices for using AI-assisted coding effectively.
If you’re new to Positron, I’ve also published two related videos: one that provides a general overview of Positron, and another that walks through configuring and using its AI assistant.
Neither of those videos are required to follow along with the above video, but they’re useful if you’d like a deeper dive into Positron itself.
Example data
The example data we’ll work with is from a Employee Satisfaction Survey Data found on Kaggle.com.
➡️ You can access the CSV data here...
Summary of AI tips
-
Treat AI suggestions as proposals, not answers: AI can quickly surface solutions, but it often over-engineers simple problems. Use your own understanding to decide whether the suggestion is appropriate for the task at hand.
-
Understand the code before accepting it: Even if AI-generated code produces the correct result, take time to read and understand how it works to avoid hidden edge cases or unintended behavior.
-
Use AI for debugging, not blind fixes: AI-assisted debugging is useful for surfacing potential causes, but simple errors (like typos or incorrect paths) are often faster to fix manually once you recognize them.
-
Prefer simplicity when possible: If a straightforward fix works, don’t replace it with a more complex AI-generated solution unless there’s a clear benefit.
-
Review and clean up AI-inserted code: After injecting AI-generated code, refactor it to match your preferred style (e.g., loading packages once rather than namespacing every function).
-
Leverage AI as a learning tool: Use AI explanations to deepen your understanding of unfamiliar code.
-
Verify results, not just outputs: Always confirm that AI-assisted transformations behave as expected by inspecting the data, not just trusting the code.
-
Use AI to document your work: AI can be helpful for generating clear, plain-English comments that explain what code is doing, improving readability and maintainability.
-
Maintain human judgment in the workflow: AI is most effective when paired with domain knowledge and best practices, rather than used as an autonomous decision-maker.
Code
library(dplyr)
survey <- read.csv("data/employee-survey.csv")
# Convert 'dept' and 'salary' to categorical (factor) variables using dplyr's mutate/across
survey <- survey |> mutate(across(c(dept, salary), as.factor))