Swirl《Programming E》练习9报错:无法找到函数‘func’求助
Hey there! I’ve run into similar head-scratching issues with Swirl exercises before—those "function not found" errors can feel frustrating, but let’s walk through some practical fixes:
Make sure you’re in the right Swirl exercise context
Swirl loads exercise-specific functions only when you’re actively in that section. If you switched away or restarted Swirl mid-exercise, try exiting withquit()(when prompted, you can skip saving the workspace if you’re unsure), then relaunch Swirl withswirl(), reselect Programming E, and pick up at exercise 9 again. This ensures the exercise’s custom functions are loaded properly.Check if you skipped defining
funcin an earlier step
Sometimes Swirl expects you to write thefuncfunction yourself in prior exercise prompts. If you rushed past that step, the function won’t exist in your workspace. Go back a few prompts (you can useskip()if needed, but it’s better to redo the definition step) and make sure you ran code like this:func <- function(dat) { # Your code here as per the exercise instructions }After defining it, run
ls()in the console to confirmfuncshows up in your workspace.Watch for typos and case sensitivity
R is strict about case and spelling! Double-check that you’re typingfunc(dat)exactly as the exercise specifies—no capital letters (likeFunc), extra characters, or misspellings. Even a tiny typo will trigger that error.Restart your entire R session
Occasionally, R’s workspace can get cluttered or have caching issues that block Swirl from loading functions correctly. Close R/RStudio entirely, reopen it, launch Swirl, and try the exercise again. This clears any leftover cruft that might be causing problems.
If none of these work, re-read the exercise prompt closely—sometimes Swirl uses slightly different function names than you might assume, so make sure you’re following the instructions to the letter.
内容的提问来源于stack exchange,提问作者Katherine Stolin

