Add or remove a document

These functions allow the caller to manipulate the collection of documents in the Google Docs account. One can upload a document from the local machine. And one can remove or delete a document from the remote repository.

uploadDoc(content, con, name, type = as.character(findType(content)), binary = FALSE, asText = FALSE, folder = NULL, replace = TRUE, ...) deleteDoc(doc, con = getConnection(auth), auth = getGoogleAuth(), ...)
the name of a local file or the actual content of a document to be uploaded.
the name of the Google document to be removed.
the CURL connection to the Google Docs API which has been authenticated. See getGoogleDocsConnection.
the name of the new document to be created (or the document to be replaced).
the type of document. This can be the MIME type (e.g. "text/csv") or the short hand, e.g. "csv", "odt", ..., capitalized or uncapitalized. The type is matched in the vector DocTypeExtensions. The caller can pass the value as an "AsIs" object, i.e. type = I("text/kml") and the type will not be matched against DocTypeExtensions. The server wil still validate the type. So this is a way of using a new type recognized by Google Docs that is not reflected in the code in this package.
a logical value indicating whether the content being uploaded is binary or not.
a logical indicating whether the value of content is to be treated as the content to be uploaded (TRUE) or the name of a file (FALSE).
additional arguments to be passed to the curlPerform call.
the auth token returned from a call to getGoogleAuth and used to initialize a connection.
the identifier for a Google Folder. This should be a GoogleFolder object, e.g., returned via getDocs. Alternatively, it can be the name of a folder and this function will call getDocs itself to obtain the folder information. Finally, it can be the URL for the folder's content, i.e. the value of the "src" element of the content slot in a GoogleFolder object. This is the /feeds/folders/... URL. To specify the folder in this way, one must use the AsIs function I to identify the content as being the URL.
a logical value. If this is TRUE, we check if there is an existing document named name. If there is, we rename it to a temporary name and attempt the upload of the new document in content. If this succeeds, the earlier document is removed. If the upload fails, the earlier document is moved back to the original name and so nothing is lost. If replace is FALSE, none of this is done and Google Docs allows documents with the same name in the same folder.

uploadDoc returns an object of class GoogleDocument describing the newly uploaded document.deleteDoc returns 0 if the operation succeeded or a CURL error if it failed.

See Also


  • uploadDoc
  • uploadDoc,data.frame-method
  • uploadDoc,character-method
  • [[<-,GoogleFolder-method
  • deleteDoc
  • deleteDoc,GoogleDocList-method
  • deleteDoc,GoogleDocumentDescription-method
  • deleteDoc,character-method

if(exists("GoogleDocsPassword")) {
          # getGoogleDocsConnection("my login", "my password")

  con = getGoogleDocsConnection(names(GoogleDocsPassword), GoogleDocsPassword)

  x = "1, 2, 3\n4, 5, 6\n"
  uploadDoc(x, con, name = "direct csv", type = "csv")

  deleteDoc("Untitled Presentation", con)

  # uploading to a folder

     # Specify the folder object
  docs = getDocs(con)
  uploadDoc(x, con, name = "boo", type = "csv", folder = docs$MyFolder)

  f = docs$MyFolder
  f[["boo1", type = 'csv']] = x

     # We'll have to lookup the folder id in the call.
  uploadDoc(x, con, name = "boo2", type = "csv", folder = "MyFolder")

    # Give the explicit URL directly
  uploadDoc(x, con, name = "boo3", type = "csv", folder = I(docs$MyFolder@content["src"]))
Documentation reproduced from package RGoogleDocs, version 0.7-0, License: BSD

Community examples

Looks like there are no examples yet.