Skip to content

Commit d360fd1

Browse files
sjentoftSusie Jentoft
andauthored
R and Python (#59)
* Added more to ignore files * Added examples for python/R integration * Added poetry env and renv for integration examples * Updated with video embeds --------- Co-authored-by: Susie Jentoft <coo@ssb.nogit config --global user.name Susie>
1 parent f8ce5e8 commit d360fd1

17 files changed

+7361
-127
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
LICENSE.md
2020
SECURITY.md
2121
.nojekyll
22+
^Python-and-R$

.gitignore

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,240 @@ rsconnect/
4949
# Quarto
5050
/website/.quarto/
5151
docs/
52+
53+
# Below from standard for SSB -
54+
*.ipynb
55+
56+
57+
# The section below is from the GitHub .gitignore template for Python:
58+
# https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore
59+
60+
# Byte-compiled / optimized / DLL files
61+
__pycache__/
62+
*.py[cod]
63+
*$py.class
64+
**/.poetry/cache/
65+
66+
# C extensions
67+
*.so
68+
69+
# Distribution / packaging
70+
.Python
71+
build/
72+
develop-eggs/
73+
dist/
74+
downloads/
75+
eggs/
76+
.eggs/
77+
lib/
78+
lib64/
79+
parts/
80+
sdist/
81+
var/
82+
wheels/
83+
share/python-wheels/
84+
*.egg-info/
85+
.installed.cfg
86+
*.egg
87+
MANIFEST
88+
89+
# PyInstaller
90+
# Usually these files are written by a python script from a template
91+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
92+
*.manifest
93+
*.spec
94+
95+
# Installer logs
96+
pip-log.txt
97+
pip-delete-this-directory.txt
98+
99+
# Unit test / coverage reports
100+
htmlcov/
101+
.tox/
102+
.nox/
103+
.coverage
104+
.coverage.*
105+
.cache
106+
nosetests.xml
107+
coverage.xml
108+
*.cover
109+
*.py,cover
110+
.hypothesis/
111+
.pytest_cache/
112+
cover/
113+
114+
# Translations
115+
*.mo
116+
*.pot
117+
118+
# Django stuff:
119+
*.log
120+
local_settings.py
121+
db.sqlite3
122+
db.sqlite3-journal
123+
124+
# Flask stuff:
125+
instance/
126+
.webassets-cache
127+
128+
# Scrapy stuff:
129+
.scrapy
130+
131+
# Sphinx documentation
132+
docs/_build/
133+
134+
# PyBuilder
135+
.pybuilder/
136+
target/
137+
138+
# Jupyter Notebook
139+
.ipynb_checkpoints
140+
141+
# IPython
142+
profile_default/
143+
ipython_config.py
144+
145+
# pyenv
146+
# For a library or package, you might want to ignore these files since the code is
147+
# intended to run in multiple environments; otherwise, check them in:
148+
# .python-version
149+
150+
# pipenv
151+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
152+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
153+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
154+
# install all needed dependencies.
155+
#Pipfile.lock
156+
157+
# UV
158+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
159+
# This is especially recommended for binary packages to ensure reproducibility, and is more
160+
# commonly ignored for libraries.
161+
#uv.lock
162+
163+
# poetry
164+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
165+
# This is especially recommended for binary packages to ensure reproducibility, and is more
166+
# commonly ignored for libraries.
167+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
168+
#poetry.lock
169+
170+
# pdm
171+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
172+
#pdm.lock
173+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
174+
# in version control.
175+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
176+
.pdm.toml
177+
.pdm-python
178+
.pdm-build/
179+
180+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
181+
__pypackages__/
182+
183+
# Celery stuff
184+
celerybeat-schedule
185+
celerybeat.pid
186+
187+
# SageMath parsed files
188+
*.sage.py
189+
190+
# Environments
191+
.env
192+
.venv
193+
env/
194+
venv/
195+
ENV/
196+
env.bak/
197+
venv.bak/
198+
199+
# Spyder project settings
200+
.spyderproject
201+
.spyproject
202+
203+
# Rope project settings
204+
.ropeproject
205+
206+
# mkdocs documentation
207+
/site
208+
209+
# mypy
210+
.mypy_cache/
211+
.dmypy.json
212+
dmypy.json
213+
214+
# Pyre type checker
215+
.pyre/
216+
217+
# pytype static type analyzer
218+
.pytype/
219+
220+
# Cython debug symbols
221+
cython_debug/
222+
223+
# PyCharm
224+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
225+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
226+
# and can be added to the global gitignore or merged into this file. For a more nuclear
227+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
228+
#.idea/
229+
230+
# Ruff stuff:
231+
.ruff_cache/
232+
233+
# PyPI configuration file
234+
.pypirc
235+
236+
# The section below is from the GitHub .gitignore template for R:
237+
# https://raw.githubusercontent.com/github/gitignore/main/R.gitignore
238+
239+
# History files
240+
.Rhistory
241+
.Rapp.history
242+
243+
# Session Data files
244+
.RData
245+
.RDataTmp
246+
247+
# User-specific files
248+
.Ruserdata
249+
250+
# Example code in package build process
251+
*-Ex.R
252+
253+
# Output files from R CMD build
254+
/*.tar.gz
255+
256+
# Output files from R CMD check
257+
/*.Rcheck/
258+
259+
# RStudio files
260+
.Rproj.user/
261+
262+
# produced vignettes
263+
vignettes/*.html
264+
vignettes/*.pdf
265+
266+
# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
267+
.httr-oauth
268+
269+
# knitr and R markdown default cache directories
270+
*_cache/
271+
/cache/
272+
273+
# Temporary files created by R markdown
274+
*.utf8.md
275+
*.knit.md
276+
277+
# R Environment Variables
278+
.Renviron
279+
280+
# pkgdown site
281+
# SSB: The directory below is commented out because default when generating documentation with Sphinx
282+
#docs/
283+
284+
# translation temp files
285+
po/*~
286+
287+
# RStudio Connect folder
288+
rsconnect/

Python-og-R/.Rprofile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source("renv/activate.R")

Python-og-R/beskytte_tabellen.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# -*- coding: utf-8 -*-
2+
# Program for å beskytte en tabell ved bruk av GaussSupression
3+
4+
# Hent inn biblioteket
5+
library(GaussSuppression)
6+
7+
# Les inn data
8+
tabell1 <- read.csv("/buckets/produkt/felles/r_og_python/tabell1.csv")
9+
10+
# Kjøre SuppressSmallCounts
11+
tabell1_protect = SuppressSmallCounts(data = tabell1, maxN = 3, freqVar = 3, dimVar = 1:2)
12+
13+
# Lagre data etterpå
14+
write.csv(tabell1_protect, file = "/buckets/produkt/felles/r_og_python/tabell1_protect.csv", row.names=FALSE)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
# Program for å beskytte en tabell ved bruk av GaussSupression
3+
4+
# Hent inn biblioteket
5+
library(GaussSuppression)
6+
7+
# Hent inn argumentene
8+
args <- commandArgs(trailingOnly = TRUE)
9+
tabell_navn <- args[1]
10+
tabell_ut <- args[2]
11+
12+
# Les inn data
13+
tabell1 <- read.csv(paste0("/buckets/produkt/felles/r_og_python/", tabell_navn, ".csv"))
14+
15+
# Kjøre SuppressSmallCounts
16+
tabell1_protect = SuppressSmallCounts(data = tabell1, maxN = 3, freqVar = 3, dimVar = 1:2)
17+
18+
# Lagre data etterpå
19+
write.csv(tabell1_protect,
20+
file = paste0("/buckets/produkt/felles/r_og_python/", tabell_ut, ".csv"),
21+
row.names=FALSE)

0 commit comments

Comments
 (0)