RStudio中运行whitebox包报错:whitebox_tools.exe未找到(文件实际存在)
What's Going On?
It looks like you've hit a common encoding snag with non-ASCII characters in file paths on Windows. Even though wbt_init() confirms whitebox_tools.exe exists, when you run functions like wbt_version(), the system call from R mangles the å in Umeå universitet into Ã¥. This leads it to search for a file at a garbled, incorrect path—hence the "not found" error, even though the executable is right where it should be.
Why This Happens
Windows often struggles with non-ASCII characters in paths when system calls are initiated from R, especially when the path includes cloud storage locations like OneDrive (which frequently have organization names with special characters). The encoding mismatch between how R stores the path and how the Windows system interprets it creates this frustrating disconnect.
Fixes to Try
Here are three proven solutions to get WhiteboxR working smoothly:
1. Reinstall WhiteboxTools to an ASCII-only path
Pick a simple directory with no special characters (like C:/R-Tools/Whitebox/), then:
- Use the
dest_dirparameter to install the binary directly there:whitebox::install_whitebox(dest_dir = "C:/R-Tools/Whitebox/") - Explicitly set the executable path in R before using any functions:
library(whitebox) wbt_set_exe_path("C:/R-Tools/Whitebox/whitebox_tools.exe") - Test it with
wbt_version()—this should resolve the error immediately.
2. Move your R library to an ASCII-only location
If your default R library path includes non-ASCII characters, relocating it can prevent similar issues down the line:
- Create a new folder like
C:/R-Library/ - Open your
.Renvironfile (useusethis::edit_r_environ()to access it easily) - Add this line to set the new default library path:
R_LIBS_USER="C:/R-Library/" - Restart R, then reinstall the
whiteboxpackage and runinstall_whitebox()again. The binary will now live in a path free of special characters.
3. Use Windows short path notation
Windows has a legacy "short path" system for compatibility that avoids non-ASCII characters. To leverage this:
- Open Command Prompt, navigate to the folder containing
whitebox_tools.exe - Run
dir /xto view short names for each folder in your path (they look likeONEDRI~1instead ofOneDrive - Umeå universitet) - Build the full short path (e.g.,
C:/Users/FRSU00~1/ONEDRI~1/Documents/R/win-library/4.1/whitebox/WBT/whitebox_tools.exe) - Set this path in R with
wbt_set_exe_path()as shown in the first solution.
Have Others Had This Problem?
Absolutely—this is a well-documented issue for WhiteboxR users on Windows, especially those with non-ASCII characters in their user profiles or OneDrive paths. Most community threads about this issue point directly to path encoding mismatches as the root cause.
内容的提问来源于stack exchange,提问作者fredrik.sundberg

