Archive

Posts Tagged ‘python’

Set a file or folder to be ignored by Dropbox

February 6, 2024 Leave a comment

Problem

You have a file/folder in your Dropbox folder that you want to keep there (on your local machine), but you don’t want to upload it to the cloud. That is, you want the Dropbox client to ignore it.

A typical use case: you have a Python project that you want to put in a virtual environment. If you create the venv/ directory in the project folder, it’s uploaded to the cloud. However, the venv/ folder can be huge and it’s reproducible. What to do if you don’t want to sync it?

Solution

The Dropbox GUI client must have an option for this but I hate those GUI interfaces. How to do it in the command line?

Well, it can be done. I found the solution here: https://help.dropbox.com/sync/ignored-files

Ignore a file/folder [set ignore]:

$ attr -s com.dropbox.ignored -V 1 'target'

Where 'target' is the file/folder you want to ignore.

Undo the ignoring (i.e., sync it again) [remove ignore]:

$ attr -r com.dropbox.ignored 'target'

For this, you need to install the attr package that makes it possible to handle extended attributes.

Links

Create a desktop icon under Ubuntu

March 3, 2022 Leave a comment

Problem

There is no easy way to add a launcher icon to the desktop under Ubuntu. A long time ago it was possible: right click on the desktop, create launcher, etc. But then they removed this feature. Why? No idea. So now if you want to create a launcher, you need to do it manually. If you are lucky, you already have an icon on the Desktop and you can make a copy of it. But it’s still painful and stupid.

Solution

It annoyed me so much that I wrote a simple script for this. It’s available here: https://github.com/jabbalaci/Bash-Utils/blob/master/add_new_desktop_icon.py .

Usage

  • put the script into the folder ~/Desktop
  • enter ~/Desktop and launch the script
  • answer three simple questions and the script will create a launcher for you
  • a launcher icon will appear on the Desktop
  • right click on the icon, allow launching, and you are done

This is a joke that one needs to write a script to accomplish such a simple task…

[R Markdown] use inline Python code

October 18, 2021 Leave a comment

Problem

You want to use inline Python code in R Markdown. Example:

1 + 1 = `r 1+1`         # 1 + 1 = 2

1 + 1 = `python 1+1`    # 1 + 1 = python 1+1

As you can see, it only works with R :( What to do?

Solution

Python is not supported in inline code, but I have the following workaround solution:

```{r setup, include=FALSE}
library(reticulate)
```

```{python include=FALSE}
result = 1 + 1
```

1 + 1 = `r py$result`    # 1 + 1 = 2

py$result means: take the value of the Python variable called result.

R Markdown installation for Linux

September 29, 2021 Leave a comment

Problem

You want to use R Markdown. How to install it?

(Inside R Markdown, you can embed Python too. Actually, that’s what I want to use.)

Solution

First, you must have R:

$ sudo apt install r-base-core

Make sure that it’s installed correctly. Start the R shell with the command “R“. Exit with Ctrl+d.

Install RStudio (optional, but recommended):

Launch RStudio. Select File -> New File -> R Markdown… RStudio will offer to install a lot of packages that are necessary for working with .Rmd files. Select Yes and let it work. It’ll take a few minutes.

To have Python support, install the package “reticulate”. Enter the following in the R shell:

> install.packages("reticulate")

Visual Studio Code support

For working with .Rmd files, you don’t have to use R Studio. Personally, I prefer VS Code. To have R support, install the extension “R” by Yuki Ueda. It provides syntax highlighting for .Rmd files and lots of other goodies.

This VS Code extension requires the R package “‘languageserver”. Install it in the R shell:

> install.packages("languageserver")

For the first time it failed for me. It turned out that the Ubuntu package libcurl-dev was missing. This is a metapackage and I had to install the package libcurl4-openssl-dev. After this, install.packages("languageserver") in the R shell succeeded.

Restart VS Code, open an .Rmd file and now everything should be OK. Right click on the file name, select Open Preview, and you should see the rendered output.

Examples

See here: https://github.com/jabbalaci/blog-assets/tree/master/20210929-Rmd

Update (20211018)

VS Code is great, but it doesn’t update the PDF. When you open a preview, it generates a temporary HTML output. If you want to update the PDF output automatically, read this post of mine.

Update (20211216)

After a system update, I got an error that some .so file was missing. In this case, launch R and issue the command “update.packages()“. This command updates all installed packages.

If you get a warning that some packages won’t be updated, try this: “update.packages(oldPkgs = old.packages())“.

I also got a warning that the permission of /usr/lib/R/library is not OK. I launched R as a normal user and I had no write permission on this folder. I changed the owner of this folder to my normal user and the issue got solved.

Update (20230128) Installing under Manjaro Linux

I installed the whole thing on a fresh Manjaro box and here are the steps I had to perform. This is a short(er) summary of everything mentioned above.

In the following, $ signifies the Bash shell and > signifies the R shell.

Install RStudio:

$ yay -S rstudio-desktop-bin

Don’t launch it yet. Verify if R is available:

$ R

Tap Ctrl-D twice to quit the R shell.

Install these packages:

$ yay -S openssl-1.1
$ yay -S texlive-core texlive-latexextra
$ yay -S gcc-fortran
$ yay -S pandoc
$ yay -S tk
$ yay -S okular

Modify the owner of /usr/lib/R/library to make it writable by you:

$ cd /usr/lib/R
$ sudo chown -R {user}:{group} library/

Where {user} is your username and {group} is your group. The value of the two may be the same.

Start RStudio:

$ /usr/lib/rstudio/rstudio &

It’s a good idea to make a launcher script for it.

In RStudio: File -> New File -> R markdown…, then choose “Yes” to install the dependencies.

RStudio will (probably) install the following R packages:

  • base64enc
  • digest
  • evaluate
  • glue
  • highr
  • htmltools
  • jsonlite
  • knitr
  • magrittr
  • markdown
  • mime
  • rmarkdown
  • stringi
  • stringr
  • xfun
  • yaml

Install the following R packages too. Remember, now > means the R shell:

> install.packages("reticulate")
> install.packages("Matrix")
> install.packages("languageserver")

Finally, update all R packages:

> update.packages()

If you get an error, you may have to redo this step:

$ cd /usr/lib/R
$ sudo chown -R {user}:{group} library/

Issue this command again:

> update.packages()

If everything went well, it won’t update anything (since everything is already up to date).

At the end, try to convert an .Rmd file to PDF:

$ Rscript -e "rmarkdown::render('test.Rmd')"

It should work.

Now that everything is installed, you can remove RStudio if you want. We’ll be able to compile .Rmd files to PDF in the command line, we won’t need RStudio for that. This step is optional:

$ yay -R rstudio-desktop-bin

Update (20230131) Installing under Ubuntu 22.04

I installed the whole thing on a fresh Ubuntu 22.04 box too. This is a short(er) summary of everything mentioned above. Note that I had problem with installing RStudio (openssl conflict), so I skipped that part. However, RStudio is not necessary, it was just optional.

In the following, $ signifies the Bash shell and R> signifies the R shell.

Here are the steps:

$ sudo apt install r-base r-base-dev
$ sudo apt install libxml2-dev
$ sudo apt install texlive
$ sudo apt install texlive-latex-extra
$ sudo apt install pandoc

Verify if R is available:

$ R

Tap Ctrl-D twice to quit the R shell.

Make the folder site-library/ writable:

$ cd /usr/local/lib/R
$ sudo chown -R {user}:{group} site-library/

Where {user} is your username and {group} is your group. The value of the two may be the same.

Install these R packages:

R> install.packages("base64enc")
R> install.packages("digest")
R> install.packages("evaluate")
R> install.packages("glue")
R> install.packages("highr")
R> install.packages("htmltools")
R> install.packages("jsonlite")
R> install.packages("knitr")
R> install.packages("magrittr")
R> install.packages("markdown")
R> install.packages("mime")
R> install.packages("rmarkdown")
R> install.packages("stringi")
R> install.packages("stringr")
R> install.packages("xfun")
R> install.packages("yaml")
R>
R> install.packages("reticulate")
R> install.packages("Matrix")
R> install.packages("languageserver")

Make these folders writable:

$ cd /usr/local/lib/R
$ sudo chown -R {user}:{group} site-library/

$ cd /usr/lib/R
$ sudo chown -R {user}:{group} library/

Update all the R packages:

R> update.packages()

Finally, try to convert an .Rmd file to PDF:

$ Rscript -e "rmarkdown::render('test.Rmd')"

It should work.

Acknowledgement

I would like to say thanks to my students, Erik Pál and Antal Svec for their help for testing the installation process under Manjaro and Ubuntu.

Links

Categories: linux Tags: , , , , ,

finding a neovim problem

February 5, 2019 Leave a comment

Neovim has a built-in command :checkhealth that will run a detailed self-diagnosis.

I had the problem that when I started neovim, I got some Python-related error concerning the package neovim (the reddit discussion is here). With :checkhealth I could find the source of the problem easily.

Categories: vim Tags: , ,

Software Carpentry

January 3, 2018 Leave a comment

Software Carpentry is a community of volunteer instructors who teach short workshops and develop lessons which empower researchers of all disciplines to learn about and improve the ways in which they create software and collaborate.” (source)

I found them today: https://github.com/swcarpentry/swcarpentry . Looks good!

Design a site like this with WordPress.com
Get started