Graphics/
在生成图形时,您应确保使用相对路径。
提供给您的代码代表 R/ 目录中的一个脚本。
本练习是课程的一部分
R 防御式编程
练习说明
- 将
read_csv()的参数改为使用相对路径。 - 将
ggsave()的参数改为使用相对路径。
交互式实操练习
通过完成这段示例代码来试试这个练习。
library("ggplot2")
library("readr")
# Show the file/directory structure
list.files(".")
# Change to relative paths and load the data
battles <- read_csv("/home/repl/survival/input/battles.csv")
g <- ggplot(battles) + geom_bar(aes(Location)) # Bar chart
# Change to relative paths and save the data
ggsave(filename = "/home/repl/survival/graphics/locations.pdf", plot = g)