if (FALSE) {
## Insert, update and delete
## Note that users must have the necessary permissions in the database
## to be able to modify data through the use of these functions
# library(Rlabkey)
newrow <- data.frame(
DisplayFld="Inserted from R"
, TextFld="how its done"
, IntFld= 98
, DoubleFld = 12.345
, DateTimeFld = "03/01/2010"
, BooleanFld= FALSE
, LongTextFld = "Four score and seven years ago"
# , AttachmentFld = NA #attachment fields not supported
, RequiredText = "Veni, vidi, vici"
, RequiredInt = 0
, Category = "LOOKUP2"
, stringsAsFactors=FALSE)
insertedRow <- labkey.insertRows("http://localhost:8080/labkey",
folderPath="/apisamples", schemaName="lists", queryName="AllTypes",
toInsert=newrow, options=list(auditBehavior="DETAILED",
auditUserComment="testing audit comment for insert"))
newRowId <- insertedRow$rows[[1]]$RowId
selectedRow<-labkey.selectRows("http://localhost:8080/labkey",
folderPath="/apisamples", schemaName="lists", queryName="AllTypes",
colFilter=makeFilter(c("RowId", "EQUALS", newRowId)))
selectedRow
updaterow=data.frame(
RowId=newRowId
, DisplayFld="Updated from R"
, TextFld="how to update"
, IntFld= 777
, stringsAsFactors=FALSE)
updatedRow <- labkey.updateRows("http://localhost:8080/labkey",
folderPath="/apisamples", schemaName="lists", queryName="AllTypes",
toUpdate=updaterow, options=list(auditBehavior="DETAILED",
auditUserComment="testing audit comment for update"))
selectedRow<-labkey.selectRows("http://localhost:8080/labkey",
folderPath="/apisamples", schemaName="lists", queryName="AllTypes",
colFilter=makeFilter(c("RowId", "EQUALS", newRowId)))
selectedRow
deleterow <- data.frame(RowId=newRowId, stringsAsFactors=FALSE)
result <- labkey.deleteRows(baseUrl="http://localhost:8080/labkey",
folderPath="/apisamples", schemaName="lists", queryName="AllTypes",
toDelete=deleterow)
str(result)
}
Run the code above in your browser using DataLab