learning R with swirl-workspace and files

   Determine which directory your R session is using as its current working directory using getwd().

  List all the objects in your local workspace using ls().例如:  

                                                                                                   ls()
                                                                                                  [1] "my_div"  "my_sqrt" "x"       "y"       "z"   

  List all the files in your working directory using list.files() or dir().例如:

learning R with swirl-workspace and files

如果我们输入?list.files()则会对这个 函数做出相应的解释,其解释是:list.files{base}  list the files in the directory/folder

 Using the args() function on a function name is also a handy way to see what arguments a function can take.例如:

learning R with swirl-workspace and files

    如果想把现在的工作区赋值给一个新的工作区old.dir,则我们可以用:old.dir <- getwd()。A lot of query functions like getwd() have the useful property that they return the answer to the question as a result of the function.

    如果想创建一个新的工作区,则我们可以用dir.create。例如:Use dir.create() to create a directory in the current working directory called "testdir".则我们可以写成: dir.create("testdir")

    设置自己的工作目录,使用setwd()。这样的话,我们可以将我们的实验都在这个目录中做完后将其删除,这就是“Take only pictures, leave only footprints”

     在工作区生成一个新的文件使用file.create()。例如我们生成一个mytest.R文件,则语法为file.create("mytest.R")

     如果要检查在工作区中,某个文件是否存在,则可以使用file.exists()看返回值。

     想要得知文件的信息,可以使用file.info()

     想要更改文件的名称,我们可以使用file.rename()。这里需要注意书写格式,本人第一次尝试了好多次!

learning R with swirl-workspace and files

因此这里需要注意要记得加分号,第一个参数为你所要修改的文件名,第二个为你修改后的文件名,分别加分号。

    使用file.remove()来删除文件。

    使用file.copy()来复制文件。例如:Make a copy of "mytest2.R" called "mytest3.R" using file.copy().

                                                  则我们应该输入:file.copy("mytest2.R","mytest3.R")前者为我们需要复制的文件名,后者为复制后的文件名称。

      Provide the relative path to the file "mytest3.R" by using file.path().

这一段关于设置路径的地方没有弄懂是要干嘛?希望大神们能够解答。好像是说构建文件和工作区的路径不同。

learning R with swirl-workspace and files

   如果我们想新建一个名为“testdir2”的目录并随之建一个名为“testdir3”的子目录,则我们的命令是: dir.create(file.path("testdir2","testdir3"),recursive=TRUE)

   这里需要注意的是对于这个公式,“recursive” 一定要注明TRUE. 如果你不注明,命令看起来是被执行了,但是实际上并不能创建你想要的新的地址。并且true一定要大写,一定要记得打分号。