rrcloud

Why do you need the [1] when calling rcloud.notebook.by.name()?


In the RCloud function rcloud.notebook.by.name(), why do you need the [1] after the function in this example:

rcloud.execute.asset(name="mtcars.R",
    notebook=rcloud.notebook.by.name(
        user="rclouddocs",
        name="Basic Functionality/Create Reusable Functions/Notebook With R Function in Assets")[1]
)

Solution

  • This function returns more than just the notebook id. It also returns any part of the path which was unconsumed by the query.

    So on rcloud.social

    rcloud.notebook.by.name(
        user="rclouddocs",
        name="Basic Functionality/Create Reusable Functions/Notebook With R Function in Assets") 
    

    returns

         id                                 extra.path
    [1,] "6c90abc418dec48ec4e9016ad0187f95" ""        
    

    But if you add more path to the end:

    rcloud.notebook.by.name(
        user="rclouddocs",
        name="Basic Functionality/Create Reusable Functions/Notebook With R Function in Assets/blablabla
    

    you get

         id                                 extra.path  
    [1,] "6c90abc418dec48ec4e9016ad0187f95" "/blablabla"
    

    This is used internally by notebook.R; it's the code that allows fetching assets by user, notebook path, and asset name, for example fetching mtcars.R from the same notebook with the following URL:

    https://rcloud.social/notebook.R/rclouddocs/Basic%20Functionality/Create%20Reusable%20Functions/Notebook%20With%20R%20Function%20in%20Assets/mtcars.R