Cognos Analytics

Cognos Analytics

Connect, learn, and share with thousands of IBM Cognos Analytics users! 

 View Only
Expand all | Collapse all

What steps are required to configure R in Cognos Juypter Notebook to use a specific repository?

  • 1.  What steps are required to configure R in Cognos Juypter Notebook to use a specific repository?

    Posted Wed April 12, 2023 12:01 PM

    Hello,
    we running JNB in an air-gapped environment and need to configure JNB to use the internal repository service.

    By modifying the file pip.conf of JNB installation the usage of the internal repository is possible (command !pip install <package> works fine in JNB)
    What file(s) are necessary to modify that it is also possible to just use the command install.packages("<PACKAGE_NAME>") in R?

    As far as I know there are files like Rprofile.site or .Rprofile, but such a file does not exist in the JNB installation (like pip.conf), so I assume they have to be created and put in the right place in the container.
    Has anyone implemented this before?

    Thanks



    ------------------------------
    Michael
    ------------------------------


  • 2.  RE: What steps are required to configure R in Cognos Juypter Notebook to use a specific repository?
    Best Answer

    Posted Thu April 13, 2023 08:05 AM

    Hey Michael, there's an .Rprofile file within /home/ca_user, however it's owned by root and cannot be modified directly in the notebook unfortunately. There is a dockerfile that you can use to overwrite the file if you wish, located at /dist/scripts/Dockerfile_server_instance. You can put a new .Rprofile in the installation directory and copy it over in the Dockerfile with a COPY command. I would just make sure that the original contents of the .Rprofile file aren't erased.



    These are the contents in text if you'd like to copy it:

    .libPaths("/home/ca_user/r_libs")
    
    # Create a hidden env in which to place the new functions
    .env <- new.env()
    
    # A function that imports reticulate and calls CADataConnector$read_data(...)
    # The "..." parameter behaves similarly to both *args and **kwargs from Python
    
    .env$CADataConnector$read_data <- function(...) {
      ca_data_connector <- reticulate::import('ca_data_connector')
      return(ca_data_connector$CADataConnector$read_data(...))
    }
    
    # A function that imports reticulate and calls CADataConnector$write_data(...)
    # The "..." parameter behaves similarly to both *args and **kwargs from Python
    
    .env$CADataConnector$write_data <- function(...) {
      ca_data_connector <- reticulate::import('ca_data_connector')
      ca_data_connector$CADataConnector$write_data(...)
    }
    
    # A function that imports reticulate and calls CADataConnector$search_data(...)
    # The "..." parameter behaves similarly to both *args and **kwargs from Python
    
    .env$CADataConnector$search_data <- function(...) {
      ca_data_connector <- reticulate::import('ca_data_connector')
      ca_data_connector$CADataConnector$search_data(...)
    }
    
    attach(.env)


    ------------------------------
    ROBERT MCAULEY
    ------------------------------



  • 3.  RE: What steps are required to configure R in Cognos Juypter Notebook to use a specific repository?

    Posted Wed April 19, 2023 07:29 AM

    Thanks for the description.

    I used the current content from file .Rprofile and added the command from the repository system and put this in file <installdir>/dist/scripts/my_Rprofile_config.
    And adjust Dockerfile_server_instance with
    # specific R configuration
    COPY my_Rprofile_config $HOME/.Rprofile
    RUN chown ca_user:users $HOME/.Rprofile